Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] [refactor] Decouple GUI source files from taichi_core target #5676

Merged
merged 16 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scripts/aot-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function build-and-smoke-test-android-aot-demo {

# Normally we checkout the master's commit Id: https://github.com/taichi-dev/taichi-aot-demo/commit/master
# As for why we need this explicit commit Id here, refer to: https://docs.taichi-lang.org/docs/master/contributor_guide#handle-special-ci-failures
cd taichi-aot-demo && git checkout c3348e1e3fc9a2bdef70b947c24510f2da29ea13 && cd -
cd taichi-aot-demo && git checkout 82aaecb9224ac24baf4abfdb5e94f1c6edb464c3 && cd -

APP_ROOT=taichi-aot-demo/implicit_fem
ANDROID_APP_ROOT=$APP_ROOT/android
Expand Down
78 changes: 19 additions & 59 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(TI_WITH_OPENGL "Build with the OpenGL backend" ON)
option(TI_WITH_CC "Build with the C backend" ON)
option(TI_WITH_VULKAN "Build with the Vulkan backend" OFF)
option(TI_WITH_DX11 "Build with the DX11 backend" OFF)
option(TI_WITH_GGUI "Build with GGUI" OFF)

# Force symbols to be 'hidden' by default so nothing is exported from the Taichi
# library including the third-party dependencies.
Expand Down Expand Up @@ -60,7 +61,6 @@ if (WIN32)
endif()
endif()

set(TI_WITH_GGUI OFF)
if(TI_WITH_VULKAN)
set(TI_WITH_GGUI ON)
endif()
Expand All @@ -76,40 +76,20 @@ if(NOT TI_WITH_LLVM)
endif()

file(GLOB TAICHI_CORE_SOURCE
"taichi/analysis/*.cpp" "taichi/analysis/*.h" #IR
"taichi/aot/*.cpp" "taichi/aot/*.h" #RT?
"taichi/codegen/*.cpp" "taichi/codegen/*.h" #CODEGEN
"taichi/analysis/*.cpp" "taichi/analysis/*.h"
"taichi/ir/*"
"taichi/jit/*"
"taichi/math/*"
"taichi/program/*"
"taichi/struct/*"
"taichi/system/*"
"taichi/transforms/*"
"taichi/gui/*"
"taichi/aot/*.cpp" "taichi/aot/*.h"
"taichi/platform/cuda/*" "taichi/platform/mac/*" "taichi/platform/windows/*"
"taichi/codegen/*.cpp" "taichi/codegen/*.h"
"taichi/runtime/*.h" "taichi/runtime/*.cpp"
"taichi/rhi/*.h" "taichi/rhi/*.cpp"
)
file(GLOB TAICHI_GGUI_SOURCE
"taichi/ui/*.cpp" "taichi/ui/*/*.cpp" "taichi/ui/*/*/*.cpp"
"taichi/ui/*/*/*/*.cpp" "taichi/ui/*/*/*/*/*.cpp" "taichi/ui/*.h"
"taichi/ui/*/*.h" "taichi/ui/*/*/*.h" "taichi/ui/*/*/*/*.h" "taichi/ui/*/*/*/*/*.h"
)
file(GLOB TAICHI_GGUI_GLFW_SOURCE
"taichi/ui/common/window_base.cpp"
"taichi/ui/backends/vulkan/window.cpp"
)

if(TI_WITH_GGUI)
add_definitions(-DTI_WITH_GGUI)

# Remove GLFW dependencies from the build for Android
if(ANDROID)
list(REMOVE_ITEM TAICHI_GGUI_SOURCE ${TAICHI_GGUI_GLFW_SOURCE})
endif()
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_GGUI_SOURCE})
endif()

if(TI_WITH_LLVM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_LLVM")
Expand Down Expand Up @@ -137,7 +117,6 @@ if (TI_WITH_CC)
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_CC_SOURCE})
endif()


# This compiles all the libraries with -fPIC, which is critical to link a static
# library into a shared lib.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down Expand Up @@ -394,19 +373,24 @@ foreach (source IN LISTS TAICHI_CORE_SOURCE)
source_group("${source_path_msvc}" FILES "${source}")
endforeach ()

message("PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
# TODO Use TI_WITH_UI to guard the compilation of this target.
# This requires refactoring on the python/export_*.cpp as well as better
# error message on the Python side.
add_subdirectory(taichi/ui)
target_link_libraries(taichi_ui PUBLIC ${CORE_LIBRARY_NAME})

if(TI_WITH_PYTHON)
message("PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
set(CORE_WITH_PYBIND_LIBRARY_NAME taichi_python)
# Cannot compile Python source code with Android, but TI_EXPORT_CORE should be set and
# Android should only use the isolated library ignoring those source code.
if (NOT ANDROID)
# NO_EXTRAS is required here to avoid llvm symbol error during build
# NO_EXTRAS is required here to avoid llvm symbol error during build
file(GLOB TAICHI_PYBIND_SOURCE
"taichi/python/*.cpp"
"taichi/python/*.h"
)
pybind11_add_module(${CORE_WITH_PYBIND_LIBRARY_NAME} NO_EXTRAS ${TAICHI_PYBIND_SOURCE})
pybind11_add_module(${CORE_WITH_PYBIND_LIBRARY_NAME} NO_EXTRAS ${TAICHI_PYBIND_SOURCE})
else()
add_library(${CORE_WITH_PYBIND_LIBRARY_NAME} SHARED)
endif ()
Expand All @@ -415,8 +399,13 @@ if(TI_WITH_PYTHON)
if (LINUX)
target_link_options(${CORE_WITH_PYBIND_LIBRARY_NAME} PUBLIC -Wl,--exclude-libs=ALL)
endif()
# It is actually possible to link with an OBJECT library
# https://cmake.org/cmake/help/v3.13/command/target_link_libraries.html?highlight=target_link_libraries#linking-object-libraries

if(TI_WITH_GGUI)
target_compile_definitions(${CORE_WITH_PYBIND_LIBRARY_NAME} PRIVATE -DTI_WITH_GGUI)
target_link_libraries(${CORE_WITH_PYBIND_LIBRARY_NAME} PRIVATE taichi_ui_vulkan)
endif()

target_link_libraries(${CORE_WITH_PYBIND_LIBRARY_NAME} PRIVATE taichi_ui)
target_link_libraries(${CORE_WITH_PYBIND_LIBRARY_NAME} PRIVATE ${CORE_LIBRARY_NAME})

target_include_directories(${CORE_WITH_PYBIND_LIBRARY_NAME}
Expand Down Expand Up @@ -457,35 +446,6 @@ if(TI_WITH_PYTHON)
LIBRARY DESTINATION ${INSTALL_LIB_DIR}/core)
endif()

if(TI_WITH_GGUI)
# PUBLIC as required by python module
target_include_directories(${CORE_LIBRARY_NAME} PUBLIC external/glm)

# Dear ImGui
add_definitions(-DIMGUI_IMPL_VULKAN_NO_PROTOTYPES)
set(IMGUI_DIR external/imgui)
file(GLOB TAICHI_IMGUI_SOURCE
${IMGUI_DIR}/backends/imgui_impl_vulkan.cpp
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
)

if(ANDROID)
list(APPEND TAICHI_IMGUI_SOURCE ${IMGUI_DIR}/backends/imgui_impl_android.cpp)
add_library(imgui ${TAICHI_IMGUI_SOURCE})
else()
list(APPEND TAICHI_IMGUI_SOURCE ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp)
add_library(imgui ${TAICHI_IMGUI_SOURCE})
target_include_directories(imgui PRIVATE external/glfw/include)
endif()

target_include_directories(imgui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends ..)
target_include_directories(imgui PRIVATE external/Vulkan-Headers/include)
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE imgui)
endif()

if (NOT APPLE)
install(FILES ${CMAKE_SOURCE_DIR}/external/cuda_libdevice/slim_libdevice.10.bc
DESTINATION ${INSTALL_LIB_DIR}/runtime)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "taichi/ui/common/field_info.h"
#include "taichi/program/program.h"
#include "taichi/program/field_info.h"

namespace taichi {

Expand Down
19 changes: 15 additions & 4 deletions taichi/ui/common/field_info.h → taichi/program/field_info.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#pragma once
#include "taichi/ui/utils/utils.h"

#include "taichi/ir/type_utils.h"
#include "taichi/ir/snode.h"
#include "taichi/rhi/device.h"
#include "taichi/program/program.h"

TI_UI_NAMESPACE_BEGIN
#define DEFINE_PROPERTY(Type, name) \
Type name; \
void set_##name(const Type &new_name) { \
name = new_name; \
} \
Type get_##name() { \
return name; \
}

namespace taichi {

namespace ui {

enum class FieldSource : int {
TaichiCuda = 0,
Expand Down Expand Up @@ -46,4 +55,6 @@ struct FieldInfo {
taichi::lang::DevicePtr get_device_ptr(taichi::lang::Program *program,
taichi::lang::SNode *snode);

TI_UI_NAMESPACE_END
} // namespace ui

} // namespace taichi
2 changes: 1 addition & 1 deletion taichi/python/export_ggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace py = pybind11;
#include "taichi/ui/backends/vulkan/scene.h"
#include "taichi/rhi/vulkan/vulkan_loader.h"
#include "taichi/rhi/arch.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/common/gui_base.h"
#include "taichi/program/ndarray.h"
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion taichi/python/export_visual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "taichi/python/export.h"
#include "taichi/util/image_io.h"
#include "taichi/gui/gui.h"
#include "taichi/ui/gui/gui.h"

TI_NAMESPACE_BEGIN

Expand Down
61 changes: 61 additions & 0 deletions taichi/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ./taichi/ui/CMakeLists.txt

add_library(taichi_ui OBJECT
gui/gui.cpp
gui/android.cpp
gui/cocoa.cpp
gui/win32.cpp
gui/x11.cpp
)

if(TI_WITH_GGUI AND NOT ANDROID)
target_sources(taichi_ui PRIVATE common/window_base.cpp)
endif()

target_include_directories(taichi_ui
PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/external/glfw/include
${PROJECT_SOURCE_DIR}/external/eigen
${PROJECT_SOURCE_DIR}/external/volk
${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include
${LLVM_INCLUDE_DIRS}
PUBLIC
${PROJECT_SOURCE_DIR}/external/glm
)

target_link_libraries(taichi_ui PRIVATE taichi_core)
target_link_libraries(taichi_ui PRIVATE taichi_common)


########################################################
### GGUI ####
########################################################
if(TI_WITH_GGUI)
# Dear ImGui
add_definitions(-DIMGUI_IMPL_VULKAN_NO_PROTOTYPES)
set(IMGUI_DIR ${PROJECT_SOURCE_DIR}/external/imgui)
file(GLOB TAICHI_IMGUI_SOURCE
${IMGUI_DIR}/backends/imgui_impl_vulkan.cpp
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
)
if(ANDROID)
list(APPEND TAICHI_IMGUI_SOURCE ${IMGUI_DIR}/backends/imgui_impl_android.cpp)
add_library(imgui ${TAICHI_IMGUI_SOURCE})
else()
list(APPEND TAICHI_IMGUI_SOURCE ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp)
add_library(imgui ${TAICHI_IMGUI_SOURCE})
target_include_directories(imgui PRIVATE ${PROJECT_SOURCE_DIR}/external/glfw/include)
endif()

target_include_directories(imgui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends ..)
target_include_directories(imgui PUBLIC ${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include)

target_link_libraries(taichi_ui PRIVATE imgui)

add_subdirectory(backends/vulkan)
target_link_libraries(taichi_ui PUBLIC taichi_ui_vulkan)
endif()
47 changes: 47 additions & 0 deletions taichi/ui/backends/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ./taichi/ui/backends/vulkan/CMakeLists.txt

add_library(taichi_ui_vulkan OBJECT)
target_sources(taichi_ui_vulkan
PRIVATE
app_context.cpp
canvas.cpp
gui.cpp
renderable.cpp
renderer.cpp
swap_chain.cpp
vertex.cpp
renderables/circles.cpp
renderables/lines.cpp
renderables/mesh.cpp
renderables/particles.cpp
renderables/scene_lines.cpp
renderables/set_image.cpp
renderables/triangles.cpp
)

if(NOT ANDROID)
target_sources(taichi_ui_vulkan PRIVATE window.cpp)
endif()

target_include_directories(taichi_ui_vulkan
PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/external/glm
${PROJECT_SOURCE_DIR}/external/eigen
${PROJECT_SOURCE_DIR}/external/volk
${PROJECT_SOURCE_DIR}/external/VulkanMemoryAllocator/include
${PROJECT_SOURCE_DIR}/external/imgui
${PROJECT_SOURCE_DIR}/external/imgui/backends
${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include
${LLVM_INCLUDE_DIRS}
PUBLIC
${PROJECT_SOURCE_DIR}/external/glfw/include
)

target_link_libraries(taichi_ui_vulkan PRIVATE taichi_core)
target_link_libraries(taichi_ui_vulkan PRIVATE taichi_common)
target_link_libraries(taichi_ui_vulkan PRIVATE imgui)

if(TI_WITH_VULKAN)
target_link_libraries(taichi_ui_vulkan PUBLIC vulkan_rhi)
endif()
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/circles.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/common/canvas_base.h"

TI_UI_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/lines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/common/canvas_base.h"

TI_UI_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/backends/vulkan/scene.h"

TI_UI_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/backends/vulkan/scene.h"

TI_UI_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/scene_lines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/backends/vulkan/scene.h"

TI_UI_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/set_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/common/canvas_base.h"
#include "taichi/rhi/device.h"

Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/backends/vulkan/renderables/triangles.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "taichi/ui/backends/vulkan/app_context.h"
#include "taichi/ui/backends/vulkan/swap_chain.h"
#include "taichi/ui/backends/vulkan/renderable.h"
#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/common/canvas_base.h"

TI_UI_NAMESPACE_BEGIN
Expand Down
2 changes: 1 addition & 1 deletion taichi/ui/common/canvas_base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "taichi/ui/common/field_info.h"
#include "taichi/program/field_info.h"
#include "taichi/ui/common/scene_base.h"
#include "taichi/ui/common/renderable_info.h"
#include "taichi/ui/utils/utils.h"
Expand Down
Loading