Skip to content

Commit

Permalink
Update android build to use webgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
sidreesshah committed Mar 5, 2025
1 parent 86e71f3 commit 14e3ae5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// com.google.android.filament.exclude-vulkan
// When set, support for Vulkan will be excluded.
//
// com.google.android.filament.include-webgpu
// When set, enables WebGPU support.
//
// com.google.android.filament.fgviewer
// When set, enables fgviewer
//
Expand Down Expand Up @@ -64,6 +67,10 @@ buildscript {
.gradleProperty("com.google.android.filament.exclude-vulkan")
.isPresent()

def includeWebGPU = providers
.gradleProperty("com.google.android.filament.include-webgpu")
.isPresent()

// TODO: Uncomment below when fgviewer is ready
// def fgviewer = providers
// .gradleProperty("com.google.android.filament.fgviewer")
Expand Down Expand Up @@ -123,6 +130,7 @@ buildscript {
"-DANDROID_STL=c++_static",
"-DFILAMENT_DIST_DIR=${filamentPath}".toString(),
"-DFILAMENT_SUPPORTS_VULKAN=${excludeVulkan ? 'OFF' : 'ON'}".toString(),
"-DFILAMENT_SUPPORTS_WEBGPU=${includeWebGPU ? 'ON' : 'OFF'}".toString(),
// TODO: Uncomment below when fgviewer is ready
// "-DFILAMENT_ENABLE_FGVIEWER=${fgviewer ? 'ON' : 'OFF'}".toString(),
"-DFILAMENT_ENABLE_MATDBG=${matdbg ? 'ON' : 'OFF'}".toString(),
Expand Down
8 changes: 8 additions & 0 deletions android/filament-android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ option(FILAMENT_SUPPORTS_VULKAN "Enables Vulkan on Android" OFF)
# option(FILAMENT_ENABLE_FGVIEWER "Enables Frame Graph Viewer" OFF)
option(FILAMENT_ENABLE_MATDBG "Enables Material debugger" OFF)
option(FILAMENT_DISABLE_MATOPT "Disables material optimizations" OFF)
option(FILAMENT_SUPPORTS_WEBGPU "Enables WebGPU on Android" OFF)

set(FILAMENT_DIR ${FILAMENT_DIST_DIR})

Expand Down Expand Up @@ -49,6 +50,12 @@ add_library(vkshaders STATIC IMPORTED)
set_target_properties(vkshaders PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libvkshaders.a)

if (FILAMENT_SUPPORTS_WEBGPU)
add_library(webgpu_dawn STATIC IMPORTED)
set_target_properties(webgpu_dawn PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libwebgpu_dawn.a)
endif()

add_library(smol-v STATIC IMPORTED)
set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libsmol-v.a)
Expand Down Expand Up @@ -132,6 +139,7 @@ target_link_libraries(filament-jni
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:filamat>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:bluevk>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:vkshaders>
$<$<STREQUAL:${FILAMENT_SUPPORTS_WEBGPU},ON>:webgpu_dawn>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:smol-v>
)

Expand Down
4 changes: 4 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ android.nonFinalResIds=false
com.google.android.filament.tools-dir=../../../out/release/filament
com.google.android.filament.dist-dir=../out/android-release/filament
com.google.android.filament.abis=all

# Below line should be enabled, if filament is built with WebGPU support
#com.google.android.filament.include-webgpu

#com.google.android.filament.matdbg
#com.google.android.filament.matnopt
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ VULKAN_ANDROID_OPTION="-DFILAMENT_SUPPORTS_VULKAN=ON"
VULKAN_ANDROID_GRADLE_OPTION=""

WEBGPU_OPTION="-DFILAMENT_SUPPORTS_WEBGPU=OFF"
WEBGPU_ANDROID_GRADLE_OPTION=""

EGL_ON_LINUX_OPTION="-DFILAMENT_SUPPORTS_EGL_ON_LINUX=OFF"

Expand Down Expand Up @@ -530,6 +531,7 @@ function build_android {
-Pcom.google.android.filament.dist-dir=../out/android-debug/filament \
-Pcom.google.android.filament.abis=${ABI_GRADLE_OPTION} \
${VULKAN_ANDROID_GRADLE_OPTION} \
${WEBGPU_ANDROID_GRADLE_OPTION} \
${MATDBG_GRADLE_OPTION} \
${MATOPT_GRADLE_OPTION} \
:filament-android:assembleDebug \
Expand Down Expand Up @@ -579,6 +581,7 @@ function build_android {
-Pcom.google.android.filament.dist-dir=../out/android-release/filament \
-Pcom.google.android.filament.abis=${ABI_GRADLE_OPTION} \
${VULKAN_ANDROID_GRADLE_OPTION} \
${WEBGPU_ANDROID_GRADLE_OPTION} \
${MATDBG_GRADLE_OPTION} \
${MATOPT_GRADLE_OPTION} \
:filament-android:assembleRelease \
Expand Down Expand Up @@ -959,6 +962,7 @@ while getopts ":hacCfgimp:q:uvWslwedtk:bx:S:X:" opt; do
;;
W)
WEBGPU_OPTION="-DFILAMENT_SUPPORTS_WEBGPU=ON"
WEBGPU_ANDROID_GRADLE_OPTION="-Pcom.google.android.filament.include-webgpu"
echo "Enable support for WebGPU(Experimental) in the core Filament library."
;;
s)
Expand Down

0 comments on commit 14e3ae5

Please sign in to comment.