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] Move opengl source files to target locations #5200

Merged
merged 11 commits into from
Jun 17, 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
21 changes: 20 additions & 1 deletion cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,25 @@ endif()
file(GLOB TAICHI_VULKAN_TEMP_SOURCE
"taichi/backends/vulkan/*.h"
"taichi/backends/vulkan/*.cpp"
"taichi/runtime/gfx/*.h"
"taichi/runtime/gfx/*.cpp"
"taichi/runtime/program_impls/vulkan/*.h"
"taichi/runtime/program_impls/vulkan/*.cpp"
)
list(REMOVE_ITEM TAICHI_CORE_SOURCE ${TAICHI_VULKAN_TEMP_SOURCE})

# TODO(#4832), Remove opengl runtime files from TAICHI_CORE_SOURCE
# Remove this after all sources are splitted into targets.
file(GLOB TAICHI_OPENGL_TEMP_SOURCE
"taichi/backends/opengl/*.h"
"taichi/backends/opengl/*.cpp"
"taichi/runtime/opengl/*.h"
"taichi/runtime/opengl/*.cpp"
"taichi/runtime/program_impls/opengl/*.h"
"taichi/runtime/program_impls/opengl/*.cpp"
)
list(REMOVE_ITEM TAICHI_CORE_SOURCE ${TAICHI_OPENGL_TEMP_SOURCE})


# TODO(#2196): Rename these CMAKE variables:
# CORE_LIBRARY_NAME --> TAICHI_ISOLATED_CORE_LIB_NAME
Expand Down Expand Up @@ -368,8 +382,13 @@ if (TI_WITH_OPENGL)
target_include_directories(${CORE_LIBRARY_NAME} PRIVATE external/SPIRV-Cross)
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE spirv-cross-glsl spirv-cross-core)

add_subdirectory(taichi/backends/opengl)
add_subdirectory(taichi/runtime/opengl)
add_subdirectory(taichi/runtime/program_impls/opengl)


target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE opengl_runtime)
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE opengl_program_impl)
endif()

if (TI_WITH_DX11)
Expand Down Expand Up @@ -409,7 +428,7 @@ if (TI_WITH_VULKAN)
# Should be removed
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE vulkan_rhi)

add_subdirectory(taichi/runtime/program_impls)
add_subdirectory(taichi/runtime/program_impls/vulkan)
target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE vulkan_program_impl)
endif ()

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

set(OPENGL_RHI opengl_rhi)
add_library(${OPENGL_RHI})
target_sources(${OPENGL_RHI}
PRIVATE
opengl_device.cpp
)

#TODO 4832, some dependencies here should not be required as they
# are build requirements of other targets.
target_include_directories(${OPENGL_RHI}
PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/external/spdlog/include
${PROJECT_SOURCE_DIR}/external/glad/include
${PROJECT_SOURCE_DIR}/external/glfw/include
${LLVM_INCLUDE_DIRS}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <string>

#include "taichi/runtime/opengl/opengl_api.h"
#include "taichi/backends/opengl/opengl_data_types.h"
#include "taichi/backends/opengl/opengl_kernel_util.h"
#include "taichi/codegen/opengl/opengl_data_types.h"
#include "taichi/runtime/opengl/opengl_kernel_util.h"
#include "taichi/ir/ir.h"
#include "taichi/ir/statements.h"
#include "taichi/ir/transforms.h"
Expand All @@ -30,12 +30,12 @@ namespace shaders {
_(arr7)

#define TI_INSIDE_OPENGL_CODEGEN
#include "taichi/backends/opengl/shaders/atomics_macro_f32.glsl.h"
#include "taichi/codegen/opengl/shaders/atomics_macro_f32.glsl.h"
#include "taichi/runtime/opengl/shaders/runtime.h"
#include "taichi/backends/opengl/shaders/random.glsl.h"
#include "taichi/backends/opengl/shaders/fast_pow.glsl.h"
#include "taichi/backends/opengl/shaders/print.glsl.h"
#include "taichi/backends/opengl/shaders/reduction.glsl.h"
#include "taichi/codegen/opengl/shaders/random.glsl.h"
#include "taichi/codegen/opengl/shaders/fast_pow.glsl.h"
#include "taichi/codegen/opengl/shaders/print.glsl.h"
#include "taichi/codegen/opengl/shaders/reduction.glsl.h"

GENERATE_OPENGL_ATOMIC_F32(data);
GENERATE_OPENGL_ATOMIC_F32(gtmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "taichi/inc/constants.h"
#include "taichi/lang_util.h"
#include "taichi/backends/opengl/struct_opengl.h"
#include "taichi/codegen/opengl/struct_opengl.h"
#include "taichi/runtime/opengl/opengl_api.h"

#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

#include "taichi/runtime/opengl/opengl_kernel_launcher.h"
#include "taichi/backends/opengl/opengl_data_types.h"
#include "taichi/codegen/opengl/opengl_data_types.h"
#include "taichi/ir/snode.h"

#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion taichi/codegen/spirv/spirv_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "taichi/ir/ir.h"
#include "taichi/util/line_appender.h"
#include "taichi/codegen/spirv/kernel_utils.h"
#include "taichi/backends/opengl/opengl_data_types.h"
#include "taichi/codegen/opengl/opengl_data_types.h"
#include "taichi/codegen/spirv/spirv_ir_builder.h"
#include "taichi/ir/transforms.h"
#include "taichi/math/arithmetic.h"
Expand Down
6 changes: 5 additions & 1 deletion taichi/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "taichi/struct/struct_llvm.h"
#include "taichi/backends/metal/api.h"
#include "taichi/backends/wasm/aot_module_builder_impl.h"
#include "taichi/backends/opengl/opengl_program.h"
#include "taichi/runtime/program_impls/opengl/opengl_program.h"
#include "taichi/backends/metal/metal_program.h"
#include "taichi/backends/cc/cc_program.h"
#include "taichi/platform/cuda/detect_cuda.h"
Expand Down Expand Up @@ -102,8 +102,12 @@ Program::Program(Arch desired_arch)
TI_ERROR("This taichi is not compiled with DX11");
#endif
} else if (config.arch == Arch::opengl) {
#ifdef TI_WITH_OPENGL
TI_ASSERT(opengl::initialize_opengl(config.use_gles));
program_impl_ = std::make_unique<OpenglProgramImpl>(config);
#else
TI_ERROR("This taichi is not compiled with OpenGL");
#endif
} else if (config.arch == Arch::cc) {
#ifdef TI_WITH_CC
program_impl_ = std::make_unique<CCProgramImpl>(config);
Expand Down
9 changes: 8 additions & 1 deletion taichi/python/export_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*******************************************************************************/

#include "taichi/backends/metal/api.h"
#include "taichi/runtime/opengl/opengl_api.h"
#include "taichi/runtime/gfx/runtime.h"
#include "taichi/backends/dx/dx_api.h"
#include "taichi/common/core.h"
Expand All @@ -29,6 +28,10 @@
#include "taichi/backends/vulkan/vulkan_loader.h"
#endif

#ifdef TI_WITH_OPENGL
#include "taichi/runtime/opengl/opengl_api.h"
#endif

#ifdef TI_WITH_CC
namespace taichi::lang::cccp {
extern bool is_c_backend_available();
Expand Down Expand Up @@ -138,8 +141,12 @@ void export_misc(py::module &m) {
m.def("toggle_python_print_buffer", [](bool opt) { py_cout.enabled = opt; });
m.def("with_cuda", is_cuda_api_available);
m.def("with_metal", taichi::lang::metal::is_metal_api_available);
#ifdef TI_WITH_OPENGL
m.def("with_opengl", taichi::lang::opengl::is_opengl_api_available,
py::arg("use_gles") = false);
#else
m.def("with_opengl", []() { return false; });
#endif
#ifdef TI_WITH_VULKAN
m.def("with_vulkan", taichi::lang::vulkan::is_vulkan_api_available);
m.def("set_vulkan_visible_device",
Expand Down
5 changes: 5 additions & 0 deletions taichi/runtime/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ add_library(opengl_runtime)
target_sources(opengl_runtime
PRIVATE
opengl_api.cpp
aot_module_builder_impl.cpp
opengl_utils.cpp
)

#TODO #4832, some path here should not be included as they are
Expand All @@ -20,3 +22,6 @@ target_include_directories(opengl_runtime
${PROJECT_SOURCE_DIR}/external/spdlog/include
${LLVM_INCLUDE_DIRS}
)

target_link_libraries(opengl_runtime PRIVATE opengl_rhi)
target_link_libraries(opengl_runtime PRIVATE glfw)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>
#include <vector>

#include "taichi/backends/opengl/opengl_program.h"
#include "taichi/runtime/program_impls/opengl/opengl_program.h"

namespace taichi {
namespace lang {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "taichi/backends/opengl/aot_module_builder_impl.h"
#include "taichi/runtime/opengl/aot_module_builder_impl.h"

#include "taichi/aot/module_data.h"
#include "taichi/backends/opengl/opengl_utils.h"
#include "taichi/runtime/opengl/opengl_utils.h"

#if !defined(TI_PLATFORM_WINDOWS)
#include <stdio.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <vector>

#include "taichi/aot/module_builder.h"
#include "taichi/backends/opengl/aot_data.h"
#include "taichi/runtime/opengl/aot_data.h"

namespace taichi {
namespace lang {
Expand Down
4 changes: 2 additions & 2 deletions taichi/runtime/opengl/opengl_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <list>

#include "taichi/backends/opengl/opengl_kernel_util.h"
#include "taichi/backends/opengl/opengl_utils.h"
#include "taichi/runtime/opengl/opengl_kernel_util.h"
#include "taichi/runtime/opengl/opengl_utils.h"
#include "taichi/runtime/opengl/shaders/runtime.h"
#include "taichi/ir/transforms.h"
#include "taichi/program/kernel.h"
Expand Down
2 changes: 1 addition & 1 deletion taichi/runtime/opengl/opengl_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "taichi/backends/device.h"
#include "taichi/runtime/opengl/opengl_kernel_launcher.h"
#include "taichi/backends/opengl/opengl_kernel_util.h"
#include "taichi/runtime/opengl/opengl_kernel_util.h"
#include "taichi/common/core.h"
#include "taichi/ir/offloaded_task_type.h"
#include "taichi/ir/transforms.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "taichi/backends/opengl/opengl_utils.h"
#include "taichi/runtime/opengl/opengl_utils.h"
#include "glad/gl.h"

namespace taichi {
Expand Down
1 change: 1 addition & 0 deletions taichi/runtime/program_impls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ./taichi/runtime/program_impls/CMakeLists.txt

add_subdirectory(vulkan)
add_subdirectory(opengl)
17 changes: 17 additions & 0 deletions taichi/runtime/program_impls/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ./taichi/runtime/program_impls/opengl/CMakeLists.txt

add_library(opengl_program_impl)
target_sources(opengl_program_impl
PRIVATE
opengl_program.cpp
)

target_include_directories(opengl_program_impl
PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/external/eigen
${PROJECT_SOURCE_DIR}/external/spdlog/include
${LLVM_INCLUDE_DIRS}
)

target_link_libraries(opengl_program_impl PRIVATE opengl_runtime)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "taichi/backends/opengl/opengl_program.h"
#include "taichi/backends/opengl/aot_module_builder_impl.h"
#include "opengl_program.h"
#include "taichi/runtime/opengl/aot_module_builder_impl.h"
using namespace taichi::lang::opengl;

namespace taichi {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include "taichi/backends/opengl/struct_opengl.h"
#include "taichi/codegen/opengl/struct_opengl.h"

#include "taichi/runtime/opengl/opengl_kernel_launcher.h"
#include "taichi/runtime/opengl/opengl_api.h"
#include "taichi/backends/opengl/codegen_opengl.h"
#include "taichi/codegen/opengl/codegen_opengl.h"

#include "taichi/system/memory_pool.h"
#include "taichi/common/logging.h"
Expand Down