From 192da1fb2a0315a3d60be36c2dd8ff057042abe4 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 14:15:48 +0800 Subject: [PATCH 01/10] Move opengl runtime, codegen and program_impl out of rhi --- .../opengl/codegen_opengl.cpp | 14 +++++++------- .../opengl/codegen_opengl.h | 2 +- .../opengl/opengl_data_types.h | 0 .../opengl/shaders/atomics_macro_f32.glsl.h | 0 .../opengl/shaders/atomics_macro_f64.glsl.h | 0 .../opengl/shaders/fast_pow.glsl.h | 0 .../opengl/shaders/indirect.glsl.h | 0 .../opengl/shaders/print.glsl.h | 0 .../opengl/shaders/random.glsl.h | 0 .../opengl/shaders/reduction.glsl.h | 0 .../opengl/struct_opengl.cpp | 0 .../opengl/struct_opengl.h | 2 +- taichi/codegen/spirv/spirv_codegen.cpp | 2 +- taichi/program/program.cpp | 2 +- .../{backends => runtime}/opengl/aot_data.h | 2 +- .../opengl/aot_module_builder_impl.cpp | 4 ++-- .../opengl/aot_module_builder_impl.h | 2 +- taichi/runtime/opengl/opengl_api.cpp | 4 ++-- taichi/runtime/opengl/opengl_api.h | 2 +- .../opengl/opengl_kernel_util.h | 0 .../opengl/opengl_utils.cpp | 2 +- .../opengl/opengl_utils.h | 0 taichi/runtime/program_impls/CMakeLists.txt | 1 + .../program_impls/opengl/CMakeLists.txt | 19 +++++++++++++++++++ .../program_impls}/opengl/opengl_program.cpp | 4 ++-- .../program_impls}/opengl/opengl_program.h | 4 ++-- 26 files changed, 43 insertions(+), 23 deletions(-) rename taichi/{backends => codegen}/opengl/codegen_opengl.cpp (99%) rename taichi/{backends => codegen}/opengl/codegen_opengl.h (94%) rename taichi/{backends => codegen}/opengl/opengl_data_types.h (100%) rename taichi/{backends => codegen}/opengl/shaders/atomics_macro_f32.glsl.h (100%) rename taichi/{backends => codegen}/opengl/shaders/atomics_macro_f64.glsl.h (100%) rename taichi/{backends => codegen}/opengl/shaders/fast_pow.glsl.h (100%) rename taichi/{backends => codegen}/opengl/shaders/indirect.glsl.h (100%) rename taichi/{backends => codegen}/opengl/shaders/print.glsl.h (100%) rename taichi/{backends => codegen}/opengl/shaders/random.glsl.h (100%) rename taichi/{backends => codegen}/opengl/shaders/reduction.glsl.h (100%) rename taichi/{backends => codegen}/opengl/struct_opengl.cpp (100%) rename taichi/{backends => codegen}/opengl/struct_opengl.h (93%) rename taichi/{backends => runtime}/opengl/aot_data.h (87%) rename taichi/{backends => runtime}/opengl/aot_module_builder_impl.cpp (98%) rename taichi/{backends => runtime}/opengl/aot_module_builder_impl.h (96%) rename taichi/{backends => runtime}/opengl/opengl_kernel_util.h (100%) rename taichi/{backends => runtime}/opengl/opengl_utils.cpp (94%) rename taichi/{backends => runtime}/opengl/opengl_utils.h (100%) create mode 100644 taichi/runtime/program_impls/opengl/CMakeLists.txt rename taichi/{backends => runtime/program_impls}/opengl/opengl_program.cpp (95%) rename taichi/{backends => runtime/program_impls}/opengl/opengl_program.h (94%) diff --git a/taichi/backends/opengl/codegen_opengl.cpp b/taichi/codegen/opengl/codegen_opengl.cpp similarity index 99% rename from taichi/backends/opengl/codegen_opengl.cpp rename to taichi/codegen/opengl/codegen_opengl.cpp index 6c9614764c810..dc4d9bad1a45d 100644 --- a/taichi/backends/opengl/codegen_opengl.cpp +++ b/taichi/codegen/opengl/codegen_opengl.cpp @@ -4,8 +4,8 @@ #include #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" @@ -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); diff --git a/taichi/backends/opengl/codegen_opengl.h b/taichi/codegen/opengl/codegen_opengl.h similarity index 94% rename from taichi/backends/opengl/codegen_opengl.h rename to taichi/codegen/opengl/codegen_opengl.h index 8e4dba27f3977..9caf9a8e46af4 100644 --- a/taichi/backends/opengl/codegen_opengl.h +++ b/taichi/codegen/opengl/codegen_opengl.h @@ -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 diff --git a/taichi/backends/opengl/opengl_data_types.h b/taichi/codegen/opengl/opengl_data_types.h similarity index 100% rename from taichi/backends/opengl/opengl_data_types.h rename to taichi/codegen/opengl/opengl_data_types.h diff --git a/taichi/backends/opengl/shaders/atomics_macro_f32.glsl.h b/taichi/codegen/opengl/shaders/atomics_macro_f32.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/atomics_macro_f32.glsl.h rename to taichi/codegen/opengl/shaders/atomics_macro_f32.glsl.h diff --git a/taichi/backends/opengl/shaders/atomics_macro_f64.glsl.h b/taichi/codegen/opengl/shaders/atomics_macro_f64.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/atomics_macro_f64.glsl.h rename to taichi/codegen/opengl/shaders/atomics_macro_f64.glsl.h diff --git a/taichi/backends/opengl/shaders/fast_pow.glsl.h b/taichi/codegen/opengl/shaders/fast_pow.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/fast_pow.glsl.h rename to taichi/codegen/opengl/shaders/fast_pow.glsl.h diff --git a/taichi/backends/opengl/shaders/indirect.glsl.h b/taichi/codegen/opengl/shaders/indirect.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/indirect.glsl.h rename to taichi/codegen/opengl/shaders/indirect.glsl.h diff --git a/taichi/backends/opengl/shaders/print.glsl.h b/taichi/codegen/opengl/shaders/print.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/print.glsl.h rename to taichi/codegen/opengl/shaders/print.glsl.h diff --git a/taichi/backends/opengl/shaders/random.glsl.h b/taichi/codegen/opengl/shaders/random.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/random.glsl.h rename to taichi/codegen/opengl/shaders/random.glsl.h diff --git a/taichi/backends/opengl/shaders/reduction.glsl.h b/taichi/codegen/opengl/shaders/reduction.glsl.h similarity index 100% rename from taichi/backends/opengl/shaders/reduction.glsl.h rename to taichi/codegen/opengl/shaders/reduction.glsl.h diff --git a/taichi/backends/opengl/struct_opengl.cpp b/taichi/codegen/opengl/struct_opengl.cpp similarity index 100% rename from taichi/backends/opengl/struct_opengl.cpp rename to taichi/codegen/opengl/struct_opengl.cpp diff --git a/taichi/backends/opengl/struct_opengl.h b/taichi/codegen/opengl/struct_opengl.h similarity index 93% rename from taichi/backends/opengl/struct_opengl.h rename to taichi/codegen/opengl/struct_opengl.h index 2d9faad8a6d5d..28a620002748c 100644 --- a/taichi/backends/opengl/struct_opengl.h +++ b/taichi/codegen/opengl/struct_opengl.h @@ -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 diff --git a/taichi/codegen/spirv/spirv_codegen.cpp b/taichi/codegen/spirv/spirv_codegen.cpp index 9a70511d0bba6..6cd92965fd5d4 100644 --- a/taichi/codegen/spirv/spirv_codegen.cpp +++ b/taichi/codegen/spirv/spirv_codegen.cpp @@ -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" diff --git a/taichi/program/program.cpp b/taichi/program/program.cpp index 6de93705647dc..100dadf952f1a 100644 --- a/taichi/program/program.cpp +++ b/taichi/program/program.cpp @@ -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" diff --git a/taichi/backends/opengl/aot_data.h b/taichi/runtime/opengl/aot_data.h similarity index 87% rename from taichi/backends/opengl/aot_data.h rename to taichi/runtime/opengl/aot_data.h index 076fdb8fa349f..e09ef3b07849d 100644 --- a/taichi/backends/opengl/aot_data.h +++ b/taichi/runtime/opengl/aot_data.h @@ -3,7 +3,7 @@ #include #include -#include "taichi/backends/opengl/opengl_program.h" +#include "taichi/runtime/program_impls/opengl/opengl_program.h" namespace taichi { namespace lang { diff --git a/taichi/backends/opengl/aot_module_builder_impl.cpp b/taichi/runtime/opengl/aot_module_builder_impl.cpp similarity index 98% rename from taichi/backends/opengl/aot_module_builder_impl.cpp rename to taichi/runtime/opengl/aot_module_builder_impl.cpp index 08a921746a4ad..6a9b49f918c4d 100644 --- a/taichi/backends/opengl/aot_module_builder_impl.cpp +++ b/taichi/runtime/opengl/aot_module_builder_impl.cpp @@ -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 diff --git a/taichi/backends/opengl/aot_module_builder_impl.h b/taichi/runtime/opengl/aot_module_builder_impl.h similarity index 96% rename from taichi/backends/opengl/aot_module_builder_impl.h rename to taichi/runtime/opengl/aot_module_builder_impl.h index b3ddd4c340067..fb2fe84354c65 100644 --- a/taichi/backends/opengl/aot_module_builder_impl.h +++ b/taichi/runtime/opengl/aot_module_builder_impl.h @@ -4,7 +4,7 @@ #include #include "taichi/aot/module_builder.h" -#include "taichi/backends/opengl/aot_data.h" +#include "taichi/runtime/opengl/aot_data.h" namespace taichi { namespace lang { diff --git a/taichi/runtime/opengl/opengl_api.cpp b/taichi/runtime/opengl/opengl_api.cpp index 27347a5cb390b..48598bf94a953 100644 --- a/taichi/runtime/opengl/opengl_api.cpp +++ b/taichi/runtime/opengl/opengl_api.cpp @@ -2,8 +2,8 @@ #include -#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" diff --git a/taichi/runtime/opengl/opengl_api.h b/taichi/runtime/opengl/opengl_api.h index 1262444178eea..58ea1cbb63bea 100644 --- a/taichi/runtime/opengl/opengl_api.h +++ b/taichi/runtime/opengl/opengl_api.h @@ -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" diff --git a/taichi/backends/opengl/opengl_kernel_util.h b/taichi/runtime/opengl/opengl_kernel_util.h similarity index 100% rename from taichi/backends/opengl/opengl_kernel_util.h rename to taichi/runtime/opengl/opengl_kernel_util.h diff --git a/taichi/backends/opengl/opengl_utils.cpp b/taichi/runtime/opengl/opengl_utils.cpp similarity index 94% rename from taichi/backends/opengl/opengl_utils.cpp rename to taichi/runtime/opengl/opengl_utils.cpp index dee9d71ae950f..b992f2eb88113 100644 --- a/taichi/backends/opengl/opengl_utils.cpp +++ b/taichi/runtime/opengl/opengl_utils.cpp @@ -1,4 +1,4 @@ -#include "taichi/backends/opengl/opengl_utils.h" +#include "taichi/runtime/opengl/opengl_utils.h" #include "glad/gl.h" namespace taichi { diff --git a/taichi/backends/opengl/opengl_utils.h b/taichi/runtime/opengl/opengl_utils.h similarity index 100% rename from taichi/backends/opengl/opengl_utils.h rename to taichi/runtime/opengl/opengl_utils.h diff --git a/taichi/runtime/program_impls/CMakeLists.txt b/taichi/runtime/program_impls/CMakeLists.txt index ab14f3f71c843..7850a5ef53640 100644 --- a/taichi/runtime/program_impls/CMakeLists.txt +++ b/taichi/runtime/program_impls/CMakeLists.txt @@ -1,3 +1,4 @@ # ./taichi/runtime/program_impls/CMakeLists.txt add_subdirectory(vulkan) +add_subdirectory(opengl) diff --git a/taichi/runtime/program_impls/opengl/CMakeLists.txt b/taichi/runtime/program_impls/opengl/CMakeLists.txt new file mode 100644 index 0000000000000..00c25d9f2edef --- /dev/null +++ b/taichi/runtime/program_impls/opengl/CMakeLists.txt @@ -0,0 +1,19 @@ +# ./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 + #${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include + #${LLVM_INCLUDE_DIRS} + ) + +#target_link_libraries(vulkan_program_impl PRIVATE vulkan_rhi) +#target_link_libraries(vulkan_program_impl PRIVATE gfx_runtime) diff --git a/taichi/backends/opengl/opengl_program.cpp b/taichi/runtime/program_impls/opengl/opengl_program.cpp similarity index 95% rename from taichi/backends/opengl/opengl_program.cpp rename to taichi/runtime/program_impls/opengl/opengl_program.cpp index a862522bca984..e4c9025bc22ad 100644 --- a/taichi/backends/opengl/opengl_program.cpp +++ b/taichi/runtime/program_impls/opengl/opengl_program.cpp @@ -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 { diff --git a/taichi/backends/opengl/opengl_program.h b/taichi/runtime/program_impls/opengl/opengl_program.h similarity index 94% rename from taichi/backends/opengl/opengl_program.h rename to taichi/runtime/program_impls/opengl/opengl_program.h index 5e0434823bf22..213c063c2aaab 100644 --- a/taichi/backends/opengl/opengl_program.h +++ b/taichi/runtime/program_impls/opengl/opengl_program.h @@ -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" From b72476ec13deadf28974a7d92fb1ec05e1cebcfc Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 15:54:45 +0800 Subject: [PATCH 02/10] Remove vulkan add subdir --- cmake/TaichiCore.cmake | 5 ++++- taichi/runtime/opengl/CMakeLists.txt | 2 ++ taichi/runtime/program_impls/opengl/CMakeLists.txt | 9 ++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmake/TaichiCore.cmake b/cmake/TaichiCore.cmake index 0c9c41e59cdd3..60fccbf990b8c 100644 --- a/cmake/TaichiCore.cmake +++ b/cmake/TaichiCore.cmake @@ -370,6 +370,9 @@ if (TI_WITH_OPENGL) add_subdirectory(taichi/runtime/opengl) target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE opengl_runtime) + + add_subdirectory(taichi/runtime/program_impls/opengl) + target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE opengl_program_impl) endif() if (TI_WITH_DX11) @@ -409,7 +412,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 () diff --git a/taichi/runtime/opengl/CMakeLists.txt b/taichi/runtime/opengl/CMakeLists.txt index f846fd8996491..fceda57df9520 100644 --- a/taichi/runtime/opengl/CMakeLists.txt +++ b/taichi/runtime/opengl/CMakeLists.txt @@ -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 diff --git a/taichi/runtime/program_impls/opengl/CMakeLists.txt b/taichi/runtime/program_impls/opengl/CMakeLists.txt index 00c25d9f2edef..6f3b6fd5fb666 100644 --- a/taichi/runtime/program_impls/opengl/CMakeLists.txt +++ b/taichi/runtime/program_impls/opengl/CMakeLists.txt @@ -9,11 +9,6 @@ target_sources(opengl_program_impl target_include_directories(opengl_program_impl PRIVATE ${PROJECT_SOURCE_DIR} - #${PROJECT_SOURCE_DIR}/external/eigen - #${PROJECT_SOURCE_DIR}/external/spdlog/include - #${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include - #${LLVM_INCLUDE_DIRS} + ${PROJECT_SOURCE_DIR}/external/eigen + ${PROJECT_SOURCE_DIR}/external/spdlog/include ) - -#target_link_libraries(vulkan_program_impl PRIVATE vulkan_rhi) -#target_link_libraries(vulkan_program_impl PRIVATE gfx_runtime) From 592b47f2eb69f8a6d274ee87384216b67b251890 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 16:42:54 +0800 Subject: [PATCH 03/10] Adapt dependencies --- cmake/TaichiCore.cmake | 20 +++++++++++++++++-- taichi/backends/opengl/CMakeLists.txt | 18 +++++++++++++++++ taichi/runtime/opengl/CMakeLists.txt | 3 +++ .../program_impls/opengl/CMakeLists.txt | 2 ++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 taichi/backends/opengl/CMakeLists.txt diff --git a/cmake/TaichiCore.cmake b/cmake/TaichiCore.cmake index 60fccbf990b8c..80ea16ef3d8ba 100644 --- a/cmake/TaichiCore.cmake +++ b/cmake/TaichiCore.cmake @@ -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 @@ -368,10 +382,12 @@ 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) - target_link_libraries(${CORE_LIBRARY_NAME} PRIVATE opengl_runtime) - 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() diff --git a/taichi/backends/opengl/CMakeLists.txt b/taichi/backends/opengl/CMakeLists.txt new file mode 100644 index 0000000000000..b72552f5d030f --- /dev/null +++ b/taichi/backends/opengl/CMakeLists.txt @@ -0,0 +1,18 @@ +# ./taichi/backends/vulkan/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. +# public dirs here are required by backends/device.cpp +target_include_directories(${OPENGL_RHI} + PRIVATE + ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/external/spdlog/include + ${PROJECT_SOURCE_DIR}/external/glad/include + ) diff --git a/taichi/runtime/opengl/CMakeLists.txt b/taichi/runtime/opengl/CMakeLists.txt index fceda57df9520..895eeb3eab930 100644 --- a/taichi/runtime/opengl/CMakeLists.txt +++ b/taichi/runtime/opengl/CMakeLists.txt @@ -22,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) diff --git a/taichi/runtime/program_impls/opengl/CMakeLists.txt b/taichi/runtime/program_impls/opengl/CMakeLists.txt index 6f3b6fd5fb666..52dfc4cc8eaf4 100644 --- a/taichi/runtime/program_impls/opengl/CMakeLists.txt +++ b/taichi/runtime/program_impls/opengl/CMakeLists.txt @@ -12,3 +12,5 @@ target_include_directories(opengl_program_impl ${PROJECT_SOURCE_DIR}/external/eigen ${PROJECT_SOURCE_DIR}/external/spdlog/include ) + +target_link_libraries(opengl_program_impl PRIVATE opengl_runtime) From 5615f169ae6d230a0b4bb17b4bdb20f93877e053 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 16:46:24 +0800 Subject: [PATCH 04/10] Minor --- taichi/backends/opengl/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/taichi/backends/opengl/CMakeLists.txt b/taichi/backends/opengl/CMakeLists.txt index b72552f5d030f..07c69ad39c7d6 100644 --- a/taichi/backends/opengl/CMakeLists.txt +++ b/taichi/backends/opengl/CMakeLists.txt @@ -1,4 +1,4 @@ -# ./taichi/backends/vulkan/CMakeLists.txt +# ./taichi/backends/opengl/CMakeLists.txt set(OPENGL_RHI opengl_rhi) add_library(${OPENGL_RHI}) @@ -9,7 +9,6 @@ target_sources(${OPENGL_RHI} #TODO 4832, some dependencies here should not be required as they # are build requirements of other targets. -# public dirs here are required by backends/device.cpp target_include_directories(${OPENGL_RHI} PRIVATE ${PROJECT_SOURCE_DIR} From ae244a40622934a8d3f51559b219b21909db79c6 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 17:38:50 +0800 Subject: [PATCH 05/10] Fix cl linking --- taichi/program/program.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/taichi/program/program.cpp b/taichi/program/program.cpp index 100dadf952f1a..986935ef9204b 100644 --- a/taichi/program/program.cpp +++ b/taichi/program/program.cpp @@ -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(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(config); From 7e5f7332b8f5b613fbc49300979bcd33b8789868 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 17:53:38 +0800 Subject: [PATCH 06/10] Resolved symbol --- taichi/python/export_misc.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/taichi/python/export_misc.cpp b/taichi/python/export_misc.cpp index 44e1f88c0e72c..000fdfd080558 100644 --- a/taichi/python/export_misc.cpp +++ b/taichi/python/export_misc.cpp @@ -138,8 +138,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_VULKAN 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", From 03631164d44cbdb433dbcfa1f67431d5259c3ab1 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 18:15:10 +0800 Subject: [PATCH 07/10] llvm include --- taichi/backends/opengl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/taichi/backends/opengl/CMakeLists.txt b/taichi/backends/opengl/CMakeLists.txt index 07c69ad39c7d6..50ccd9ce8068a 100644 --- a/taichi/backends/opengl/CMakeLists.txt +++ b/taichi/backends/opengl/CMakeLists.txt @@ -14,4 +14,5 @@ target_include_directories(${OPENGL_RHI} ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/spdlog/include ${PROJECT_SOURCE_DIR}/external/glad/include + ${LLVM_INCLUDE_DIRS} ) From 85b1c6b1965a7dc9863ca1c1dc4db03bb3072f0b Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 18:25:52 +0800 Subject: [PATCH 08/10] Minor --- taichi/runtime/program_impls/opengl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/taichi/runtime/program_impls/opengl/CMakeLists.txt b/taichi/runtime/program_impls/opengl/CMakeLists.txt index 52dfc4cc8eaf4..7bc2b517583c8 100644 --- a/taichi/runtime/program_impls/opengl/CMakeLists.txt +++ b/taichi/runtime/program_impls/opengl/CMakeLists.txt @@ -11,6 +11,7 @@ target_include_directories(opengl_program_impl ${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) From b68fecbdc13428faf69a2f896c2810b4b219b4c1 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 19:23:50 +0800 Subject: [PATCH 09/10] Fix --- taichi/python/export_misc.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/taichi/python/export_misc.cpp b/taichi/python/export_misc.cpp index 000fdfd080558..f814a95245afc 100644 --- a/taichi/python/export_misc.cpp +++ b/taichi/python/export_misc.cpp @@ -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" @@ -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(); @@ -138,7 +141,7 @@ 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_VULKAN +#ifdef TI_WITH_OPENGL m.def("with_opengl", taichi::lang::opengl::is_opengl_api_available, py::arg("use_gles") = false); #else From 8d670629cf79058d50f5264360709778100adec1 Mon Sep 17 00:00:00 2001 From: Bo Qiao Date: Fri, 17 Jun 2022 19:46:57 +0800 Subject: [PATCH 10/10] Needs GLFW --- taichi/backends/opengl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/taichi/backends/opengl/CMakeLists.txt b/taichi/backends/opengl/CMakeLists.txt index 50ccd9ce8068a..4d94993cfe389 100644 --- a/taichi/backends/opengl/CMakeLists.txt +++ b/taichi/backends/opengl/CMakeLists.txt @@ -14,5 +14,6 @@ target_include_directories(${OPENGL_RHI} ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/external/spdlog/include ${PROJECT_SOURCE_DIR}/external/glad/include + ${PROJECT_SOURCE_DIR}/external/glfw/include ${LLVM_INCLUDE_DIRS} )