📜 ⬆️ ⬇️

Running Bullet Physics physics engine on Android x86


Photo source
The constant growth of computing power of mobile devices contributes to the development of mobile games. In the mobile segment, a whole class of games has emerged that is renowned for realistic graphics and believable physics. Effects like a grenade explosion in a shooter, a car drift in a race falls on the shoulders of a physics engine. The physics engine is based on mathematical models that are calculated during the game. As a rule, these are computational tasks and the attractiveness of the game depends on how quickly and efficiently the physics engine handles them.
This article shows how to build and port the Bullet Physics physics engine to the Android platform based on the Intel Atom processor.

Bullet Physics


Bullet Physics Library is a real-time physics engine that is actively used in computer games, movies, 3D modeling programs, as a component of other game engines, and in many other more specific cases. In mid-2011, a version appeared that supports the Android OS and includes functions optimized for ARM NEON.
Bullet Physics is going under the architecture of ARM out of the box. Such an application on phones with an Intel Atom processor will work through an emulator.
DeviceARM versionx86 version
Samsung Galaxy tab 3 10.130 FPS60 FPS

Table 1. Performance comparison (FPS - frames per second) of the ARM and x86 versions of the demo application from Bullet Physics.
Table 1 shows a comparison of the launches of an application compiled for different architectures. Measurements were made using the Intel GPA graphics profiling tool. In order to achieve maximum performance and performance on devices based on Intel Atom - the application must be ported to the x86 architecture.
Increasing the speed of physics calculation in his game, the developer gets an additional time frame budget, which he can spend either on more realistic graphics or on a more physical model.

Training


To build and port we need:

The whole process will take place on Windows, for Linux / Mac OS will not be fundamentally different. We will produce test launches on the Lenovo K900 and Samsung Galaxy Tab 3 10.1. Both devices are based on the Intel Atom Z2460 processor.
Attached to the article is a script that performs all the described actions automatically. Next, consider how to assemble Bullet Physics in manual mode.

Assembly


First we build and run the PfxApp_1_Simple demo application under ARM.
image
Figure 1. PfxApp_1_Simple demo application (Samsung Galaxy tab 3 10.1 device).
Let's get the main component of the physics engine - the PfxLibrary library. To do this, go to the project directory of the library:
<BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary\jni 

<BulletPhysics> is the path along which bullet-2.80-rev2531 is located. In this directory, open the file “Android.mk”, find and change the variable
 LOCAL_PATH := <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects 

Next, open the console. In the console, go on the way
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary 

and execute the command:
 ndk-build 

We compiled the PfxLibrary library under armeabi-v7a.
Now we will build the demo application itself. To do this, go to the directory
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple\jni 

In this directory, open the file “Android.mk”, change the variable
 LOCAL_PATH := “<BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects 

Next, open the console. In the console, go to the project directory of the application on the way
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple 

and execute the “ndk-build” command. In order to run the assembled PfxApp_1_Simple application on the device, we will use Eclipse. In Eclipse, we import the project:
File => Import => Android => Existing Android Code Into Workspace => Browse ... => \ bullet-2.80-rev2531 \ Extras \ PhysicsEffects \ project \ Android \ PfxApp_1_Simple \ ”=> OK => Finish
and run the application on the device. To do this, right-click on the project and click: Run As => Android Application.
image
Figure 2. Launching an application from the Eclipse IDE.
The PfxApp_1_Simple application started but works in emulation mode.

Porting


Build and run PfxApp_1_Simple under x86. First we port the PfxLibrary library under x86. To do this, return to the library project directory.
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary\jni 

Open the file “Application.mk”, in which we will change the variable
 APP_ABI := x86 

Then open the file “Android.mk”, in which we will change the variables
 LOCAL_PATH := <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -DUSE_PTHREADS –pthread LOCAL_ARM_NEON := false 

and remove the lines from LOCAL_SRC_FILES to remove the source files optimized for ARM Neon:
 src/base_level/solver/pfx_constraint_row_solver_neon.cpp include/vecmath/neon/vectormath_neon_assembly_implementations.S 

Rebuild the physics engine. In the console, we proceed along the path:
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary 

and execute the “ndk-build” command. We compiled a PfxLibrary library for x86. Now we will build the application itself under x86. To do this, go to the project directory application
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple\jni 

In this directory, open the file “Application.mk”, change the variable
 APP_ABI := x86 

Then open the file “Android.mk”, in which we will change the variables
 LOCAL_PATH := “<BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects LOCAL_SRC_FILES := project/Android/PfxLibrary/obj/local/x86/libpfxlibrary.a LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) LOCAL_ARM_NEON := false 

and remove lines from LOCAL_SRC_FILES, such as
  “sample/test_ARM_NEON_performance/neon_dot_product.S \”, “sample/test_ARM_NEON_performance/neon_cross_product.S \”, “sample/test_ARM_NEON_performance/neon_matrix4_operator_multiply.S \”, “sample/test_ARM_NEON_performance/neon_matrix3_operator_multiply.S \”, “sample/test_ARM_NEON_performance/neon_orthoInverse_transform3.S \”, “sample/test_ARM_NEON_performance/neon_transform3_operator_multiply.S \”, “sample/test_ARM_NEON_performance/neon_transpose_matrix3.S \”, “sample/test_ARM_NEON_performance/test_neon_cross_product.cpp \”, “sample/test_ARM_NEON_performance/test_neon_dot_product.cpp \”, “sample/test_ARM_NEON_performance/test_neon_matrix3_operator_multiply.cpp \”, “sample/test_ARM_NEON_performance/test_neon_matrix4_operator_multiply.cpp \”, “sample/test_ARM_NEON_performance/test_neon_orthoInverse_transform3.cpp \”, “sample/test_ARM_NEON_performance/test_neon_transform3_operator_multiply.cpp \”, “sample/test_ARM_NEON_performance/test_neon_transpose_matrix3.cpp \”, “sample/test_ARM_NEON_performance/test_neon_solve_linear_constraint_row.cpp”. 

Next, in the console go to the project directory on the way
 <BulletPhysics>\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple 

and execute the “ndk-build” command. Run the application on the device.
To check the result, the application used APK Info .
image
Figure 3. Screenshots of APK Info (Lenovo K900 device).

Conclusion


The article provides step-by-step instructions on how to build and port the Bullet Physics physics engine. The result of successful porting to the x86 architecture, for a specific example, can be considered a twofold acceleration of physics calculations, as a result, an increase in the frame refresh rate (FPS).

About the authors


Ilya Kryukov (ilya.krjukov@intel.com)
Denis Smirnov (denis.smirnov@intel.com)

')

Source: https://habr.com/ru/post/206004/


All Articles