Skip to content

Commit

Permalink
[vulkan] Add Vulkan API (#2299)
Browse files Browse the repository at this point in the history
* [vulkan] Add Vulkan API

* fix

* support osx

* [skip ci] enforce code format

Co-authored-by: Taichi Gardener <[email protected]>
  • Loading branch information
k-ye and taichi-gardener committed May 6, 2021
1 parent a4279bd commit 531e8e3
Show file tree
Hide file tree
Showing 5 changed files with 824 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ option(USE_STDCPP "Use -stdlib=libc++" OFF)
option(TI_WITH_CUDA "Build with the CUDA backend" ON)
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)

if(UNIX AND NOT APPLE)
# Handy helper for Linux
# https://stackoverflow.com/a/32259072/12003165
set(LINUX TRUE)
endif()

if (APPLE)
if (TI_WITH_CUDA)
Expand Down Expand Up @@ -41,6 +48,7 @@ file(GLOB TAICHI_CUDA_SOURCE "taichi/backends/cuda/*.cpp" "taichi/backends/cuda/
file(GLOB TAICHI_METAL_SOURCE "taichi/backends/metal/*.h" "taichi/backends/metal/*.cpp" "taichi/backends/metal/shaders/*")
file(GLOB TAICHI_OPENGL_SOURCE "taichi/backends/opengl/*.h" "taichi/backends/opengl/*.cpp" "taichi/backends/opengl/shaders/*")
file(GLOB TAICHI_CC_SOURCE "taichi/backends/cc/*.h" "taichi/backends/cc/*.cpp")
file(GLOB TAICHI_VULKAN_SOURCE "taichi/backends/vulkan/*.h" "taichi/backends/vulkan/*.cpp")

list(REMOVE_ITEM TAICHI_CORE_SOURCE ${TAICHI_BACKEND_SOURCE})

Expand Down Expand Up @@ -72,6 +80,12 @@ if (TI_WITH_CC)
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_CC_SOURCE})
endif()


if (TI_WITH_VULKAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_VULKAN")
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_VULKAN_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 @@ -172,6 +186,17 @@ if (TI_WITH_CUDA)
target_link_libraries(${LIBRARY_NAME} ${llvm_ptx_libs})
endif()

if (TI_WITH_VULKAN)
# Vulkan libs
# https://cmake.org/cmake/help/latest/module/FindVulkan.html
# https://github.com/PacktPublishing/Learning-Vulkan/blob/master/Chapter%2003/HandShake/CMakeLists.txt
find_package(Vulkan REQUIRED)
message(STATUS "Vulkan_INCLUDE_DIR=${Vulkan_INCLUDE_DIR}")
message(STATUS "Vulkan_LIBRARY=${Vulkan_LIBRARY}")
include_directories(${Vulkan_INCLUDE_DIR})
target_link_libraries(${CORE_LIBRARY_NAME} ${Vulkan_LIBRARY})
endif ()

# Optional dependencies

if (APPLE)
Expand Down
1 change: 1 addition & 0 deletions misc/prtags.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lang" : "Language and syntax",
"metal" : "Metal backend",
"opengl" : "OpenGL backend",
"vulkan" : "Vulkan backend",
"misc" : "Miscellaneous",
"std" : "Standard library",
"opt" : "IR optimization passes",
Expand Down
Loading

0 comments on commit 531e8e3

Please sign in to comment.