Commit 19a2a5eb authored by Aaron Bray's avatar Aaron Bray
Browse files

ENH: Vulkan is now working with new build system

parent 7bc37205
......@@ -5,6 +5,10 @@ include(imstkAddExternalProject)
imstk_add_external_project( glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.2.1
CMAKE_ARGS
-DGLFW_BUILD_DOCS:BOOL=OFF
-DGLFW_BUILD_EXAMPLES:BOOL=OFF
-DGLFW_BUILD_TESTS:BOOL=OFF
RELATIVE_INCLUDE_PATH ""
DEPENDENCIES ""
#VERBOSE
......
......@@ -5,29 +5,17 @@ if(NOT DEFINED VulkanSDK_ROOT_DIR OR NOT EXISTS ${VulkanSDK_ROOT_DIR})
set(VulkanSDK_ROOT_DIR "$ENV{VULKAN_SDK}" CACHE PATH "Path to Vulkan SDK install directory." FORCE)
endif()
if(NOT EXISTS ${VulkanSDK_ROOT_DIR})
message(FATAL_ERROR "\nCan not support Vulkan renderer without Vulkan SDK.\nSet VulkanSDK_ROOT_DIR to Vulkan SDK installation directory.\n\n")
message(FATAL_ERROR "\nCannot support Vulkan renderer without Vulkan SDK.\nSet VulkanSDK_ROOT_DIR to Vulkan SDK installation directory.\n\n")
endif()
include(imstkFind)
#-----------------------------------------------------------------------------
# Find path
# Find All Headers and Libraries for VulkanSDK
#-----------------------------------------------------------------------------
find_path(VulkanSDK_INCLUDE_DIR
NAMES
vulkan/vulkan.h
PATHS
${VulkanSDK_ROOT_DIR}/Include
)
mark_as_advanced(VulkanSDK_INCLUDE_DIR)
#-----------------------------------------------------------------------------
# Find library
#-----------------------------------------------------------------------------
find_library(VulkanSDK_LIBRARY
NAMES
vulkan-1
PATHS
${VulkanSDK_ROOT_DIR}/Lib
)
mark_as_advanced(VulkanSDK_LIBRARY)
imstk_find_header(VulkanSDK vulkan/vulkan.h)
imstk_find_libary(VulkanSDK vulkan-1)
imstk_find_package(VulkanSDK)
set(VulkanSDK_LIBRARIES ${VulkanSDK_LIBRARY})
\ No newline at end of file
#message(STATUS "VulkanSDK include : ${VULKANSDK_INCLUDE_DIRS}")
#message(STATUS "VulkanSDK libraries : ${VULKANSDK_LIBRARIES}")
......@@ -13,5 +13,3 @@ endif()
#message(STATUS "g3log include : ${G3LOG_INCLUDE_DIRS}")
#message(STATUS "g3log libraries : ${G3LOG_LIBRARIES}")
include(imstkFind)
#-----------------------------------------------------------------------------
# Find path
# Find All Headers and Libraries for g3log
#-----------------------------------------------------------------------------
find_path(glfw_INCLUDE_DIR
NAMES
GLFW/glfw3.h
PATH_SUFFIXES
include
)
mark_as_advanced(glfw_INCLUDE_DIR)
message(STATUS "glfw_INCLUDE_DIR : ${glfw_INCLUDE_DIR}")
#-----------------------------------------------------------------------------
# Find library
#-----------------------------------------------------------------------------
find_library(glfw_LIBRARY
NAMES
glfw3
)
mark_as_advanced(glfw_LIBRARY)
#message(STATUS "glfw_LIBRARY : ${glfw_LIBRARY}")
set(glfw_LIBRARIES ${glfw_LIBRARY})
#-----------------------------------------------------------------------------
# Find package
#-----------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(glfw
REQUIRED_VARS
glfw_INCLUDE_DIR
glfw_LIBRARIES)
imstk_find_header(glfw glfw/glfw3.h)
imstk_find_libary(glfw glfw3)
imstk_find_package(glfw)
#-----------------------------------------------------------------------------
# If missing target, create it
#-----------------------------------------------------------------------------
if(GLFW_FOUND AND NOT TARGET glfw)
add_library(glfw INTERFACE IMPORTED)
set_target_properties(glfw PROPERTIES
INTERFACE_LINK_LIBRARIES "${glfw_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${glfw_INCLUDE_DIR}"
)
endif()
#message(STATUS "glfw include : ${GLFW_INCLUDE_DIRS}")
#message(STATUS "glfw libraries : ${GLFW_LIBRARIES}")
include(imstkFind)
#-----------------------------------------------------------------------------
# Find path
# Find All Headers and Libraries for glm
#-----------------------------------------------------------------------------
find_path(gli_INCLUDE_DIR
NAMES
gli/gli.hpp
)
mark_as_advanced(gli_INCLUDE_DIR)
message(STATUS "gli_INCLUDE_DIR : ${gli_INCLUDE_DIR}")
#-----------------------------------------------------------------------------
# Find package
#-----------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(gli
REQUIRED_VARS
gli_INCLUDE_DIR)
imstk_find_header(gli gli/gli.hpp)
imstk_find_header_package(gli)
#-----------------------------------------------------------------------------
# If missing target, create it
#-----------------------------------------------------------------------------
if(GLM_FOUND AND NOT TARGET gli)
add_library(gli INTERFACE IMPORTED)
set_target_properties(gli PROPERTIES
INTERFACE_LINK_LIBRARIES "${gli_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${gli_INCLUDE_DIR}"
)
endif()
#message(STATUS "gli include : ${GLI_INCLUDE_DIRS}")
\ No newline at end of file
......@@ -4,8 +4,6 @@ include(imstkFind)
#-----------------------------------------------------------------------------
imstk_find_header(glm glm/glm.hpp)
imstk_find_libary(glm g3logger)
imstk_find_package(glm)
imstk_find_header_package(glm)
#message(STATUS "glm include : ${GLM_INCLUDE_DIRS}")
#message(STATUS "glm libraries : ${GLM_LIBRARIES}")
#-----------------------------------------------------------------------------
# Compile Shaders
#-----------------------------------------------------------------------------
function(compileShaders sourceShader binaryShader)
add_custom_command(
TARGET ${PROJECT_NAME}
COMMAND glslangvalidator -V ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/${sourceShader} -o ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/${binaryShader})
endfunction()
function(CopyAndCompileShaders)
if( iMSTK_USE_Vulkan )
file(COPY ${CMAKE_SOURCE_DIR}/Source/Rendering/VulkanRenderer/VulkanShaders
DESTINATION ${PROJECT_BINARY_DIR}/Shaders)
# Mesh shaders
compileShaders(Mesh/mesh_vert.vert Mesh/mesh_vert.spv)
compileShaders(Mesh/mesh_tesc.tesc Mesh/mesh_tesc.spv)
compileShaders(Mesh/mesh_tese.tese Mesh/mesh_tese.spv)
compileShaders(Mesh/mesh_frag.frag Mesh/mesh_frag.spv)
compileShaders(Mesh/decal_vert.vert Mesh/decal_vert.spv)
compileShaders(Mesh/decal_frag.frag Mesh/decal_frag.spv)
compileShaders(Mesh/shadow_vert.vert Mesh/shadow_vert.spv)
compileShaders(Mesh/shadow_frag.frag Mesh/shadow_frag.spv)
compileShaders(Mesh/depth_frag.frag Mesh/depth_frag.spv)
# Post processing shaders
compileShaders(PostProcessing/HDR_tonemap_frag.frag PostProcessing/HDR_tonemap_frag.spv)
compileShaders(PostProcessing/postprocess_vert.vert PostProcessing/postprocess_vert.spv)
compileShaders(PostProcessing/postprocess_frag.frag PostProcessing/postprocess_frag.spv)
compileShaders(PostProcessing/sss_frag.frag PostProcessing/sss_frag.spv)
compileShaders(PostProcessing/composite_frag.frag PostProcessing/composite_frag.spv)
compileShaders(PostProcessing/bloom_threshold_frag.frag PostProcessing/bloom_threshold_frag.spv)
compileShaders(PostProcessing/blur_horizontal_frag.frag PostProcessing/blur_horizontal_frag.spv)
compileShaders(PostProcessing/blur_vertical_frag.frag PostProcessing/blur_vertical_frag.spv)
compileShaders(PostProcessing/bloom_threshold_frag.frag PostProcessing/bloom_threshold_frag.spv)
compileShaders(PostProcessing/ao_frag.frag PostProcessing/ao_frag.spv)
compileShaders(PostProcessing/bilateral_blur_horizontal_frag.frag PostProcessing/bilateral_blur_horizontal_frag.spv)
compileShaders(PostProcessing/bilateral_blur_vertical_frag.frag PostProcessing/bilateral_blur_vertical_frag.spv)
compileShaders(PostProcessing/depth_downscale_frag.frag PostProcessing/depth_downscale_frag.spv)
file(COPY ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders
DESTINATION ${CMAKE_PROGRAM_PATH}/Shaders)
else( iMSTK_USE_Vulkan )
file(COPY ${CMAKE_SOURCE_DIR}/Source/Rendering/VTKRenderer/VTKShaders
DESTINATION ${PROJECT_BINARY_DIR}/Shaders)
file(COPY ${CMAKE_SOURCE_DIR}/Source/Rendering/VTKRenderer/VTKShaders
DESTINATION ${CMAKE_PROGRAM_PATH}/Shaders)
endif()
endfunction()
\ No newline at end of file
#-----------------------------------------------------------------------------
# Compile Shaders
#-----------------------------------------------------------------------------
add_custom_target(VulkanShaders)
function(compileShaders sourceShader binaryShader)
add_custom_command(
TARGET ${PROJECT_NAME}
COMMAND glslangvalidator -V ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/${sourceShader} -o ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/${binaryShader})
TARGET VulkanShaders
COMMAND ${VulkanSDK_ROOT_DIR}/bin/glslangvalidator -V ${Vulkan_Shaders}/${sourceShader} -o ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/${binaryShader})
endfunction()
function(CopyAndCompileShaders)
if( iMSTK_USE_Vulkan )
file(COPY ${CMAKE_SOURCE_DIR}/Source/Rendering/VulkanRenderer/VulkanShaders
DESTINATION ${PROJECT_BINARY_DIR}/Shaders/VulkanShaders)
set(Vulkan_Shaders "${CMAKE_SOURCE_DIR}/Source/Rendering/VulkanRenderer/VulkanShaders")
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/mesh")
# Mesh shaders
compileShaders(Mesh/mesh_vert.vert Mesh/mesh_vert.spv)
compileShaders(Mesh/mesh_tesc.tesc Mesh/mesh_tesc.spv)
compileShaders(Mesh/mesh_tese.tese Mesh/mesh_tese.spv)
compileShaders(Mesh/mesh_frag.frag Mesh/mesh_frag.spv)
compileShaders(Mesh/decal_vert.vert Mesh/decal_vert.spv)
compileShaders(Mesh/decal_frag.frag Mesh/decal_frag.spv)
compileShaders(Mesh/particle_vert.vert Mesh/particle_vert.spv)
compileShaders(Mesh/particle_frag.frag Mesh/particle_frag.spv)
compileShaders(Mesh/shadow_vert.vert Mesh/shadow_vert.spv)
compileShaders(Mesh/shadow_frag.frag Mesh/shadow_frag.spv)
compileShaders(Mesh/depth_frag.frag Mesh/depth_frag.spv)
compileShaders(mesh/mesh_vert.vert mesh/mesh_vert.spv)
compileShaders(mesh/mesh_tesc.tesc mesh/mesh_tesc.spv)
compileShaders(mesh/mesh_tese.tese mesh/mesh_tese.spv)
compileShaders(mesh/mesh_frag.frag mesh/mesh_frag.spv)
compileShaders(mesh/decal_vert.vert mesh/decal_vert.spv)
compileShaders(mesh/decal_frag.frag mesh/decal_frag.spv)
compileShaders(mesh/particle_vert.vert mesh/particle_vert.spv)
compileShaders(mesh/particle_frag.frag mesh/particle_frag.spv)
compileShaders(mesh/shadow_vert.vert mesh/shadow_vert.spv)
compileShaders(mesh/shadow_frag.frag mesh/shadow_frag.spv)
compileShaders(mesh/depth_frag.frag mesh/depth_frag.spv)
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/Shaders/VulkanShaders/PostProcessing")
# Post processing shaders
compileShaders(PostProcessing/HDR_tonemap_frag.frag PostProcessing/HDR_tonemap_frag.spv)
compileShaders(PostProcessing/postprocess_vert.vert PostProcessing/postprocess_vert.spv)
......
......@@ -13,23 +13,34 @@ macro(imstk_find_header package header)
if (${num_extra_args} GREATER 0)
list(GET extra_macro_args 0 sub_dir)
endif ()
unset(_INCLUDE_DIR)
find_path(_INCLUDE_DIR
unset(_SEARCH_DIR)
if(${package}_ROOT_DIR)
set(_SEARCH_DIR ${${package}_ROOT_DIR})
else()
set(_SEARCH_DIR ${CMAKE_INSTALL_PREFIX})
endif()
#message(STATUS "Using search dir : ${_SEARCH_DIR}/include/${sub_dir}")
find_path(${package}_INCLUDE_DIR
NAMES
${header}
PATHS
${CMAKE_INSTALL_PREFIX}/include/${sub_dir}
${_SEARCH_DIR}/include/${sub_dir}
NO_DEFAULT_PATH
)
#message(STATUS "${package}_INCLUDE_DIR : ${${package}_INCLUDE_DIR}")
if(_INCLUDE_DIR AND sub_dir)
set(_INCLUDE_DIR ${_INCLUDE_DIR}/${sub_dir})
unset(${PACKAGE}_INCLUDE_DIRS)
if (EXISTS ${${package}_INCLUDE_DIR}/${header})
string(TOUPPER ${package} PACKAGE)
list(APPEND ${PACKAGE}_INCLUDE_DIRS ${${package}_INCLUDE_DIR})
mark_as_advanced(${PACKAGE}_INCLUDE_DIRS)
else()
message(FATAL_ERROR "Could not find ${${package}_INCLUDE_DIR}/${header}")
endif()
string(TOUPPER ${package} PACKAGE)
list(APPEND ${PACKAGE}_INCLUDE_DIRS ${_INCLUDE_DIR})
mark_as_advanced(${PACKAGE}_INCLUDE_DIRS)
unset(${package}_INCLUDE_DIR CACHE)
endmacro()
#-----------------------------------------------------------------------------
......@@ -49,12 +60,20 @@ macro(imstk_find_libary package library)
#message(STATUS "${package} changing debug_postfix to ${debug_postfix}")
endif()
unset(_SEARCH_DIR)
if(${package}_ROOT_DIR)
set(_SEARCH_DIR ${${package}_ROOT_DIR})
else()
set(_SEARCH_DIR ${CMAKE_INSTALL_PREFIX})
endif()
string(TOUPPER ${package} PACKAGE)
find_library(${PACKAGE}_LIBRARY_${library}-RELEASE
NAMES
${library}
lib${library}
PATHS ${CMAKE_INSTALL_PREFIX}/lib
PATHS ${_SEARCH_DIR}/lib
NO_DEFAULT_PATH
)
if (EXISTS ${${PACKAGE}_LIBRARY_${library}-RELEASE})
......@@ -69,7 +88,7 @@ macro(imstk_find_libary package library)
NAMES
${library}${debug_postfix}
lib${library}${debug_postfix}
PATHS ${CMAKE_INSTALL_PREFIX}/lib
PATHS ${_SEARCH_DIR}/lib
NO_DEFAULT_PATH
)
if (EXISTS ${${PACKAGE}_LIBRARY_${library}-DEBUG})
......
......@@ -232,8 +232,11 @@ endif()
find_package( VTK REQUIRED CONFIG )
# Vulkan
set(Vulkan "") # Target name for dependencies
if( ${PROJECT_NAME}_USE_Vulkan )
set(Vulkan "VulkanSDK")
find_package( VulkanSDK REQUIRED)
add_definitions( -DiMSTK_USE_Vulkan )
......
......@@ -18,6 +18,11 @@
project(Example-CD-ManualCDWithOctree)
# Uses VTK Viewer
if(iMSTK_USE_Vulkan)
return()
endif()
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
......@@ -32,13 +37,14 @@ add_executable(${PROJECT_NAME} ManualCDWithOctreeExample.cpp
#-----------------------------------------------------------------------------
SET_TARGET_PROPERTIES (${PROJECT_NAME} PROPERTIES FOLDER Examples)
#-----------------------------------------------------------------------------
# Add shaders
#-----------------------------------------------------------------------------
include(imstkCopyAndCompileShaders)
CopyAndCompileShaders()
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager apiUtilities)
#--------------------------------------------------------
# Set MSVC working directory to the install/bin directory
#-----------------------------------------------------------------------------
if(MSVC) # Configure running executable out of MSVC
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${iMSTK_INSTALL_BIN_DIR}")
endif()
......@@ -16,6 +16,12 @@
#
###########################################################################
# Uses VTK Viewer
if(iMSTK_USE_Vulkan)
return()
endif()
project(Example-DebugRendering)
#-----------------------------------------------------------------------------
......
......@@ -16,6 +16,12 @@
#
###########################################################################
# Uses VTK Viewer
if(iMSTK_USE_Vulkan)
return()
endif()
project(Example-Octree)
#-----------------------------------------------------------------------------
......
......@@ -16,6 +16,11 @@
#
###########################################################################
# Uses VTK Text Status Manager
if(iMSTK_USE_Vulkan)
return()
endif()
project(Example-PBDCollision-ManyDragons)
#-----------------------------------------------------------------------------
......
......@@ -16,6 +16,11 @@
#
###########################################################################
# Uses VTK Text Status Manager
if(iMSTK_USE_Vulkan)
return()
endif()
project(Example-SPHFluid-BallDrop)
#-----------------------------------------------------------------------------
......
......@@ -16,6 +16,11 @@
#
###########################################################################
# Uses VTK Text Status Manager
if(iMSTK_USE_Vulkan)
return()
endif()
project(Example-SPHFluid-BunnyShape)
#-----------------------------------------------------------------------------
......
......@@ -16,6 +16,11 @@
#
###########################################################################
# Uses VTK Text Status Manager
if(iMSTK_USE_Vulkan)
return()
endif()
project(Example-SPHFluid-HighViscousity)
#-----------------------------------------------------------------------------
......
......@@ -32,7 +32,7 @@ if(iMSTK_USE_Vulkan)
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager)
target_link_libraries(${PROJECT_NAME} SimulationManager apiUtilities)
#-----------------------------------------------------------------------------
# Associate external data
......
......@@ -32,7 +32,7 @@ if(iMSTK_USE_Vulkan)
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager)
target_link_libraries(${PROJECT_NAME} SimulationManager apiUtilities)
#-----------------------------------------------------------------------------
# Associate external data
......
......@@ -106,7 +106,7 @@ else()
GUIOverlay
Materials)
set(RENDERING_LIBRARIES
${VulkanSDK_LIBRARIES}
${Vulkan}
glfw
gli)
if (iMSTK_ENABLE_VR)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment