Skip to content

Commit 8ed6e31

Browse files
authored
Merge branch 'android' into erfan_merge
2 parents 7889d26 + 35b9511 commit 8ed6e31

File tree

12 files changed

+125
-69
lines changed

12 files changed

+125
-69
lines changed

3rdparty/openssl/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ elseif(ANDROID) # cross-compile
5757
# ATTENTION - it used to work but ENV variable doesn't work while building https://cmake.org/cmake/help/latest/command/set.html#set-environment-variable, TODO check after changes one more time
5858
add_custom_command(
5959
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/lib/libcrypto.a" "${CMAKE_CURRENT_BINARY_DIR}/build/lib/libssl.a"
60-
COMMAND make clean
6160
# not sure if linux-generic64 is right (https://stackoverflow.com/questions/26779531/openssl-for-android-x86-64-and-mips64)
6261
# but android-x86_64 is not even recognized (should be according to this https://github.com/openssl/openssl/blob/master/NOTES-ANDROID.md)
6362
COMMAND "${PERL_EXECUTABLE}" "${_COPY_BIN_SOURCE_}/Configure" linux-generic64 no-asm no-shared -D__ANDROID_API__=${ANDROID_API_LEVEL} --openssldir=${CMAKE_CURRENT_BINARY_DIR}/build
@@ -120,4 +119,4 @@ else()
120119
"${CMAKE_CURRENT_BINARY_DIR}/build/lib/libcrypto.a"
121120
"${CMAKE_CURRENT_BINARY_DIR}/build/lib/libssl.a"
122121
)
123-
endif()
122+
endif()

CMakeLists.txt

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,65 @@ cmake_minimum_required(VERSION 3.20)
77
cmake_policy(SET CMP0072 OLD) #not yet, would need to get pointers to all OpenGL functions
88
set(OpenGL_GL_PREFERENCE LEGACY)
99
#cmake_policy(SET CMP )
10-
option(NBL_BUILD_ANDROID "Build for Android?" OFF)
10+
set(NBL_BUILD_ANDROID OFF)
1111

12-
if(DEFINED CMAKE_TOOLCHAIN_FILE) # TODO - validate paths due to CMake path-policy (errors when no path passed in)
13-
cmake_path(GET CMAKE_TOOLCHAIN_FILE FILENAME _NBL_CMAKE_TOOLCHAIN_FILENAME_)
12+
if(DEFINED CMAKE_TOOLCHAIN_FILE)
13+
14+
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
15+
cmake_path(GET CMAKE_TOOLCHAIN_FILE FILENAME _NBL_CMAKE_TOOLCHAIN_FILENAME_)
16+
else()
17+
message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE as '${CMAKE_TOOLCHAIN_FILE}' is invalid!")
18+
endif()
1419

1520
if(${_NBL_CMAKE_TOOLCHAIN_FILENAME_} STREQUAL "android.toolchain.cmake")
1621
message(STATUS "Found Android toolchain! Validating...")
1722

18-
set(_NBL_SUPPORTED_NDK_ "android-ndk-r22b") # supported NDK version
19-
set(_NBL_SUPPORTED_ABI_ "x86_64") # supported ABI
20-
21-
# quering ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_}/${_NBL_SUPPORTED_NDK_}/build/cmake/android.toolchain.cmake
22-
cmake_path(GET CMAKE_TOOLCHAIN_FILE PARENT_PATH _NBL_TOOLCHAIN_NDK_CMAKE_DIRECTORY_)
23-
cmake_path(GET _NBL_TOOLCHAIN_NDK_CMAKE_DIRECTORY_ PARENT_PATH _NBL_TOOLCHAIN_NDK_BUILD_DIRECTORY_)
24-
cmake_path(GET _NBL_TOOLCHAIN_NDK_BUILD_DIRECTORY_ PARENT_PATH _NBL_TOOLCHAIN_NDK_ROOT_DIRECTORY_)
25-
cmake_path(GET _NBL_TOOLCHAIN_NDK_ROOT_DIRECTORY_ PARENT_PATH _NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_)
26-
27-
string(LENGTH ${CMAKE_TOOLCHAIN_FILE} _NBL_CMAKE_TOOLCHAIN_FILE_LENGTH_)
28-
string(LENGTH ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_} _NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_LENGTH_)
29-
math(EXPR _NBL_PARENT_NDK_TO_TOOLCHAIN_FILE_LENGTH_ "${_NBL_CMAKE_TOOLCHAIN_FILE_LENGTH_} - ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_LENGTH_}" OUTPUT_FORMAT DECIMAL)
30-
string(SUBSTRING ${CMAKE_TOOLCHAIN_FILE} ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_LENGTH_} ${_NBL_PARENT_NDK_TO_TOOLCHAIN_FILE_LENGTH_} _NBL_PARENT_NDK_TO_TOOLCHAIN_FILEPATH_)
31-
32-
if(${_NBL_PARENT_NDK_TO_TOOLCHAIN_FILEPATH_} STREQUAL "/${_NBL_SUPPORTED_NDK_}/build/cmake/android.toolchain.cmake")
33-
message(STATUS "Found Android NDK '${_NBL_SUPPORTED_NDK_}' is appropriate!")
34-
else()
35-
message(FATAL_ERROR "Found Android NDK version isn't appropriate. Use '${_NBL_SUPPORTED_NDK_}'!")
36-
endif()
23+
set(_NBL_SUPPORTED_ABI_
24+
"x86_64"
25+
# "arm64-v8a" in future
26+
)
3727

38-
if(EXISTS "${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_}/build-tools")
39-
if(DEFINED ANDROID_ABI)
40-
if(${ANDROID_ABI} STREQUAL ${_NBL_SUPPORTED_ABI_})
41-
message(STATUS "Supported '${_NBL_SUPPORTED_ABI_}' ABI!")
42-
43-
else()
44-
message(FATAL_ERROR "Found '${ANDROID_ABI}' isn't appropriate. Use '${_NBL_SUPPORTED_ABI_}'!")
28+
if(DEFINED ANDROID_ABI) # see _NBL_SUPPORTED_ABI_
29+
set(FOUND 0)
30+
foreach(CURRENT_ABI IN LISTS _NBL_SUPPORTED_ABI_)
31+
if("${CURRENT_ABI}" STREQUAL ${ANDROID_ABI})
32+
message(STATUS "Selecting found ${CURRENT_ABI} ABI!")
33+
set(FOUND 1)
34+
break()
4535
endif()
36+
endforeach()
37+
38+
if(NOT FOUND)
39+
message(FATAL_ERROR "Selected ${ANDROID_ABI} isn't appropriate. Supported ABIs: ${_NBL_SUPPORTED_ABI_}!")
4640
else()
47-
message(STATUS "Could not find 'ANDROID_ABI', using supported ABI: '${_NBL_SUPPORTED_ABI_}'")
48-
set(ANDROID_ABI ${_NBL_SUPPORTED_ABI_} CACHE INTERNAL "" FORCE)
41+
unset(FOUND)
4942
endif()
43+
else()
44+
message(FATAL_ERROR "ANDROID_ABI must be specified at the very beginning of execution!")
45+
endif()
5046

51-
message(STATUS "'${_NBL_SUPPORTED_NDK_}' located in Android SDK path. Building Nabla with Android toolchain!")
47+
if(NOT DEFINED ANDROID_PLATFORM) # android-28
48+
message(FATAL_ERROR "ANDROID_PLATFORM must be specified at the very beginning of execution!")
49+
endif()
50+
51+
include(${CMAKE_TOOLCHAIN_FILE})
52+
53+
if(${ANDROID_NDK_MAJOR} LESS 22)
54+
message(FATAL_ERROR "Update your NDK to at least 22. We don't support ${ANDROID_NDK_REVISION} NDK version!")
55+
endif()
5256

53-
set(ANDROID_SDK_ROOT_PATH "${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_}")
54-
set(ANDROID_NDK_ROOT_PATH ${ANDROID_SDK_ROOT_PATH}/${_NBL_SUPPORTED_NDK_})
55-
56-
set(NBL_BUILD_ANDROID ON)
57-
set(_NBL_ANDROID_VALIDATED_ ON)
58-
else()
59-
message(FATAL_ERROR "${_NBL_SUPPORTED_NDK_} must be placed in Android SDK path!")
57+
# note that we assume NDK has been installed using Android Studio, so the existing paths should look as followning:
58+
# ${ANDROID_SDK_ROOT_PATH}/ndk/${ANDROID_NDK_REVISION}/build/cmake/android.toolchain.cmake
59+
60+
set(ANDROID_NDK_ROOT_PATH ${CMAKE_ANDROID_NDK})
61+
get_filename_component(ANDROID_SDK_ROOT_PATH "${ANDROID_NDK_ROOT_PATH}/../../" ABSOLUTE)
62+
63+
if(EXISTS "${ANDROID_SDK_ROOT_PATH}/build-tools")
64+
message(STATUS "Building Nabla with ${ANDROID_NDK_REVISION} NDK!")
6065
endif()
66+
67+
set(NBL_BUILD_ANDROID ON)
68+
set(_NBL_ANDROID_VALIDATED_ ON)
6169
endif()
6270

6371
# TODO - another toolchains in future
@@ -118,9 +126,6 @@ if(NBL_BUILD_ANDROID)
118126

119127
#option(STRIP_ANDROID_LIBRARY "Strip the resulting android library" OFF)
120128

121-
if(NOT ANDROID_PLATFORM)
122-
set(ANDROID_PLATFORM "android-25")
123-
endif()
124129
string(SUBSTRING
125130
"${ANDROID_PLATFORM}"
126131
8 # length of "android-"
@@ -151,7 +156,11 @@ if(NBL_BUILD_ANDROID)
151156
unset(__buildTools)
152157
endif()
153158
set(ANDROID_BUILD_TOOLS "${ANDROID_SDK_ROOT_PATH}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}")
159+
if(MSVC)
154160
set(ANDROID_JAVA_BIN "${JAVA_HOME}")
161+
else()
162+
set(ANDROID_JAVA_BIN "${JAVA_HOME}/bin")
163+
endif()
155164
set(ANDROID_JAVA_RT_JAR "${JAVA_HOME}/jre/lib/rt.jar")
156165

157166
set(ANDROID_APK_TARGET_ID "" CACHE STRING "The Target ID to build the APK for like 'android-99', use <android list targets> to choose another one.")

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Contact ***[@devshgraphicsprogramming](https://github.com/devshgraphicsprogrammi
177177
- **[CMake](https://cmake.org/download/)**
178178
- **[MSVC](https://visualstudio.microsoft.com/pl/downloads/)** or **[GCC](https://sourceforge.net/projects/mingw-w64/)**
179179
- **[Vulkan SDK](https://vulkan.lunarg.com/sdk/home)**
180-
- **[Perl](https://www.perl.org/get.html)**
180+
- **[Perl 5.28 executable version](https://www.perl.org/get.html)**
181181
- **[NASM](https://www.nasm.us/pub/nasm/releasebuilds/?C=M;O=D)**
182182
- **[Python 3.8](https://www.python.org/downloads/release/python-380/)** or later
183183

@@ -208,20 +208,27 @@ After dealing with *CUDA* installing just install *Optix SKD*.
208208
**Required:**
209209

210210
- **[Android Studio](https://developer.android.com/studio)**
211-
- **[NDK r22b](https://developer.android.com/ndk/downloads#stable-downloads)**
212-
- **[Java 8](https://www.java.com/download/)**
211+
- **[JDK 8](https://www.java.com/download/)**
213212

214-
The first step is to install Android Studio and Java 8. When done, extract NDK r22b into *Android SDK root directory* usually located at `C:/Users/<your_user>/AppData/Local/AndroidSdk`. If you however can't find it, open Android Studio and go to **File** and **Project Structure** that will show you where your Android SDKs are installed.
213+
The first step is to install Android Studio and JDK 8. When done, open Android Studio and navigate to **Tools** -> **SDK Manager** -> **System Settings** -> **Android SDK**.
214+
Select *SDK Platforms* and install proper individual SDK components - install Android version with Android API level you will be targeting. Then switch to *SDK Tools* and make sure to install **Android SDK Build-Tools 32** and **NDK (Side by side)** - it's a *requirement*! Also you must make sure that your **JAVA_HOME** enviroment variable is set to proper JDK installation path.
215215

216-
Now you can begin CMake generating. On Android Build there is an extra optional Ninja generator available. *Important note is that Nabla Android Build has been performed and tested so far on Windows as cross compile OS with **ninja** generator and on Linux as cross compile OS with **makefile** and **ninja** generators.* Before configuring you need to specify toolchain file for cross-compiling by passing path to `android.toolchain.cmake`. You can find it in NDK directory in `build/cmake/android.toolchain.cmake` and according to example of Android SDK root directory path it should look entirely like `C:/Users/<your_user>/AppData/Local/AndroidSdk/android-ndk-r22b/build/cmake/android.toolchain.cmake`.
216+
Now you can begin CMake'ing. We use **Ninja** generator tools as a generator for building Nabla for Android on both Windows and Linux Host-OSes. *Note that Nabla Android build has been performed and tested so far on Windows as cross compile OS with **Ninja** generator and on Linux as cross compile OS with **Makefile** and **Ninja** generators, but we recommend using **Ninja** for both OSes.*
217+
218+
Before configuring CMake you must add 2 cache variables:
219+
220+
- **ANDROID_PLATFORM**
221+
- **ANDROID_ABI**
222+
223+
**ANDROID_PLATFORM** is a target API platform that you pass as `android-x` where `x` is your android API level (you can pass 28 for instance). **ANDROID_ABI** is Application Binary Interface and note, that we support only `x86_64` currently. Those 2 cache variables *must be* specified before CMake configuration. Having done it you can specify toolchain file for cross-compiling by passing path to `android.toolchain.cmake`. You can find it in Android Studio's SDK directory in `ndk/<version>/build/cmake/android.toolchain.cmake`. Basically the entire path should look like this one `C:/Users/<your_user>/AppData/Local/AndroidSdk/ndk/<version>/build/cmake/android.toolchain.cmake`. With all of this feel free to generate.
217224

218225
Having Nabla generated you need to enter build directory, launch the terminal and type `cmake --build . --target Nabla -j4 -v` or if you want build android sample example you would type `cmake --build . --target android_sample_apk -j4 -v`. The android sample example produces *.apk* file you can use for debugging and profiling.
219226

220-
**Note:** each example provided by the engine builds as an executable with non-cross builds and with target of a name called *"a_target"*, in following example above it would be *"android_sample"*. When building cross-compile for android **to produce the APK file you need to add *"_apk"* postfix to the "*a_target"***, because "*a_target*" gets built then as a library.
227+
**Note:** each example provided by the engine builds as an executable with non-cross builds and with target of a name called `a_target`, in following example above it would be `android_sample`. When building cross-compile for android **to produce the APK file you need to add `_apk` postfix to the `a_target`, because `a_target` gets built then as a library.
221228

222229
#### Chrome Book SDK version
223230

224-
In order for the chromebook to work with the apk you build you need to install the right SDK version. Go to *Tools -> SDK Manager ->System and Settings -> Android SDK* then Select the *SDK Platforms* tab and tick the "Show Packake Details" checkbox in the bottom-right corner. After that select *Android 9.0 (Pie) -> Android SDK Platform 28* and hit "OK".
231+
In order for the chromebook to work with the apk you build you need to install the right SDK version. Go to **Tools** -> **SDK Manager** -> **System Settings** -> **Android SDK** then select the *SDK Platforms* tab and tick the "Show Packake Details" checkbox in the bottom-right corner. After that select *Android 9.0 (Pie) -> Android SDK Platform 28* and hit "OK".
225232

226233
#### Chrome Book upload
227234

cmake/common.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ macro(nbl_android_create_apk _TARGET)
364364
)
365365
set(D8_SCRIPT "${ANDROID_BUILD_TOOLS}/d8.bat")
366366
if(NOT EXISTS ${D8_SCRIPT})
367-
set(DEX_COMMAND ${ANDROID_BUILD_TOOLS}/dx --dex --output=bin/classes.dex ./obj)
367+
set(DEX_COMMAND ${ANDROID_BUILD_TOOLS}/d8 ./obj/eu/devsh/${TARGET_NAME}/Loader.class --output ./bin/)
368368
else()
369369
set(DEX_COMMAND ${D8_SCRIPT} --output ./bin/ ./obj/eu/devsh/${TARGET_NAME}/*.class)
370370
endif()
@@ -587,4 +587,4 @@ endmacro()
587587

588588
macro(write_source_definitions NBL_FILE NBL_WRAPPER_CODE_TO_WRITE)
589589
file(WRITE "${NBL_FILE}" "${NBL_WRAPPER_CODE_TO_WRITE}")
590-
endmacro()
590+
endmacro()

examples_tests/52.SystemTest/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,6 @@ int main(int argc, char** argv)
306306
}
307307
};
308308

309-
auto arch = system->openFileArchive(CWD.generic_string() + "test.zip");
310-
system->mount(std::move(arch), "arch");
311309
auto bigarch = system->openFileArchive(CWD.generic_string() + "../../media/sponza.zip");
312310
system->mount(std::move(bigarch), "sponza");
313311

include/matrix4SIMD.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,28 @@ class matrix4SIMD// : public AlignedBase<_NBL_SIMD_ALIGNMENT> don't inherit from
323323

324324
bool isBoxInFrustum(const aabbox3d<float>& bbox);
325325

326+
bool perspectiveTransformVect(core::vectorSIMDf& inOutVec)
327+
{
328+
transformVect(inOutVec);
329+
const bool inFront = inOutVec[3] > 0.f;
330+
inOutVec /= inOutVec.wwww();
331+
return inFront;
332+
}
333+
334+
core::vector2di fragCoordTransformVect(const core::vectorSIMDf& _in, const core::dimension2du& viewportDimensions)
335+
{
336+
core::vectorSIMDf pos(_in);
337+
pos.w = 1.f;
338+
if (perspectiveTransformVect(pos))
339+
core::vector2di(-0x80000000, -0x80000000);
340+
341+
pos[0] *= 0.5f;
342+
pos[1] *= 0.5f;
343+
pos[0] += 0.5f;
344+
pos[1] += 0.5f;
345+
346+
return core::vector2di(pos[0] * float(viewportDimensions.Width), pos[1] * float(viewportDimensions.Height));
347+
}
326348

327349
static inline matrix4SIMD buildProjectionMatrixPerspectiveFovRH(float fieldOfViewRadians, float aspectRatio, float zNear, float zFar);
328350
static inline matrix4SIMD buildProjectionMatrixPerspectiveFovLH(float fieldOfViewRadians, float aspectRatio, float zNear, float zFar);

include/nbl/system/ISystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class ISystem : public core::IReferenceCounted
372372
bool deleteDirectory(const system::path& p)
373373
{
374374
if (std::filesystem::exists(p))
375-
return std::filesystem::remove(p);
375+
return std::filesystem::remove_all(p);
376376
else
377377
return false;
378378
}

include/nbl/ui/CWindowManagerWin32.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,16 @@ namespace nbl::ui
295295
case ERT_CHANGE_CURSOR_VISIBILITY:
296296
{
297297
auto& params = req.changeCursorVisibilityParam;
298-
ShowCursor(params.visible);
298+
if(params.visible)
299+
{
300+
int ret = ShowCursor(true);
301+
while (ret < 0) ret = ShowCursor(true);
302+
}
303+
else
304+
{
305+
int ret = ShowCursor(false);
306+
while (ret >= 0) ret = ShowCursor(false);
307+
}
299308
break;
300309
}
301310
}
@@ -313,6 +322,10 @@ namespace nbl::ui
313322
{
314323
req.destroyWindowParam = std::move(params);
315324
}
325+
else if constexpr (std::is_same_v<RequestParams, SRequestParams_ChangeCursorVisibility&>)
326+
{
327+
req.changeCursorVisibilityParam = std::move(params);
328+
}
316329
}
317330

318331
bool wakeupPredicate() const { return true; }

include/nbl/video/utilities/IDrawIndirectAllocator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#ifndef _NBL_VIDEO_I_DRAW_INDIRECT_ALLOCATOR_H_INCLUDED_
66
#define _NBL_VIDEO_I_DRAW_INDIRECT_ALLOCATOR_H_INCLUDED_
77

8-
9-
#include "nbl/core/alloc/GeneralPurposeAddressAllocator.h"
8+
#include "nbl/core/alloc/GeneralpurposeAddressAllocator.h"
109

1110
#include "nbl/video/utilities/CPropertyPool.h"
1211
#include "nbl/video/utilities/CPropertyPoolHandler.h"
@@ -183,4 +182,4 @@ class IDrawIndirectAllocator : public core::IReferenceCounted
183182

184183
}
185184

186-
#endif
185+
#endif

src/nbl/asset/utils/ISPIRVOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ nbl::core::smart_refctd_ptr<ICPUBuffer> ISPIRVOptimizer::optimize(const uint32_t
3434
&spvtools::CreateSimplificationPass,
3535
&spvtools::CreateVectorDCEPass,
3636
&spvtools::CreateDeadInsertElimPass,
37-
&spvtools::CreateAggressiveDCEPass,
37+
//&spvtools::CreateAggressiveDCEPass,
3838
&spvtools::CreateDeadBranchElimPass,
3939
&spvtools::CreateBlockMergePass,
4040
&spvtools::CreateLocalMultiStoreElimPass,

0 commit comments

Comments
 (0)