From 11fbc47ae029422e869516040a68fdf05a28f3a7 Mon Sep 17 00:00:00 2001 From: Sreekanth Arikatla <sreekanth.arikatla@kitware.com> Date: Tue, 10 Jul 2018 16:17:32 -0400 Subject: [PATCH] BUG: Place the shader compilation at appropriate place --- CMake/imstkCopyAndCompileShaders.cmake | 49 +++++++++++++++++++ Examples/Audio/CMakeLists.txt | 8 +++ Examples/BoneDrilling/CMakeLists.txt | 6 +++ Examples/CMakeLists.txt | 4 +- Examples/CameraController/CMakeLists.txt | 6 +++ Examples/DeformableBody/CMakeLists.txt | 6 +++ Examples/ExtractSurface/CMakeLists.txt | 6 +++ Examples/GeometryTransforms/CMakeLists.txt | 6 +++ Examples/Graph/CMakeLists.txt | 6 +++ .../LaparoscopicToolController/CMakeLists.txt | 6 +++ Examples/MeshIO/CMakeLists.txt | 8 ++- Examples/MshVegaIO/CMakeLists.txt | 6 +++ Examples/ObjectController/CMakeLists.txt | 6 +++ Examples/PBDVolume/CMakeLists.txt | 6 +++ Examples/Picking/CMakeLists.txt | 6 +++ Examples/Rendering/CMakeLists.txt | 6 +++ Examples/Screenshot/CMakeLists.txt | 6 +++ Examples/Viewer/CMakeLists.txt | 6 +++ Examples/VirtualCoupling/CMakeLists.txt | 6 +++ Examples/VulkanDecals/CMakeLists.txt | 6 +++ .../CMakeLists.txt | 6 +++ 21 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 CMake/imstkCopyAndCompileShaders.cmake diff --git a/CMake/imstkCopyAndCompileShaders.cmake b/CMake/imstkCopyAndCompileShaders.cmake new file mode 100644 index 000000000..254bdcc02 --- /dev/null +++ b/CMake/imstkCopyAndCompileShaders.cmake @@ -0,0 +1,49 @@ +#----------------------------------------------------------------------------- +# 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 diff --git a/Examples/Audio/CMakeLists.txt b/Examples/Audio/CMakeLists.txt index 303c6e51e..da16f9c1b 100644 --- a/Examples/Audio/CMakeLists.txt +++ b/Examples/Audio/CMakeLists.txt @@ -34,10 +34,18 @@ else() SimulationManager SFML) endif() + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data #----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() list(APPEND FILE_LIST sound/,REGEX:.*) imstk_add_data(${PROJECT_NAME} ${FILE_LIST}) diff --git a/Examples/BoneDrilling/CMakeLists.txt b/Examples/BoneDrilling/CMakeLists.txt index c586bccf4..f02bc45e8 100644 --- a/Examples/BoneDrilling/CMakeLists.txt +++ b/Examples/BoneDrilling/CMakeLists.txt @@ -36,6 +36,12 @@ if(iMSTK_USE_OMNI) SimulationManager SFML) endif() + + #----------------------------------------------------------------------------- + # Add shaders + #----------------------------------------------------------------------------- + include(imstkCopyAndCompileShaders) + CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index bcbabd300..53892158d 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -56,8 +56,6 @@ foreach(subdir ${subDirs}) endforeach() #----------------------------------------------------------------------------- -# Shaders +# Add external data #----------------------------------------------------------------------------- -include(imstkCopyAndCompileShaders) -CopyAndCompileShaders() imstk_add_data(${PROJECT_NAME} ${FILE_LIST}) \ No newline at end of file diff --git a/Examples/CameraController/CMakeLists.txt b/Examples/CameraController/CMakeLists.txt index f68c4594f..f5a0b1bd5 100644 --- a/Examples/CameraController/CMakeLists.txt +++ b/Examples/CameraController/CMakeLists.txt @@ -28,6 +28,12 @@ if(iMSTK_USE_OMNI) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + + #----------------------------------------------------------------------------- + # Add shaders + #----------------------------------------------------------------------------- + include(imstkCopyAndCompileShaders) + CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/DeformableBody/CMakeLists.txt b/Examples/DeformableBody/CMakeLists.txt index c70123780..3cca576ce 100644 --- a/Examples/DeformableBody/CMakeLists.txt +++ b/Examples/DeformableBody/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} DeformableBody.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/ExtractSurface/CMakeLists.txt b/Examples/ExtractSurface/CMakeLists.txt index 6678f44cc..9dc0023c5 100644 --- a/Examples/ExtractSurface/CMakeLists.txt +++ b/Examples/ExtractSurface/CMakeLists.txt @@ -22,6 +22,12 @@ project(Example-ExtractSurface) # Create executable #----------------------------------------------------------------------------- add_executable(${PROJECT_NAME} ExtractSurface.cpp) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Link libraries to executable diff --git a/Examples/GeometryTransforms/CMakeLists.txt b/Examples/GeometryTransforms/CMakeLists.txt index ae90d695c..56aa29c3e 100644 --- a/Examples/GeometryTransforms/CMakeLists.txt +++ b/Examples/GeometryTransforms/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} GeometryTransforms.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/Graph/CMakeLists.txt b/Examples/Graph/CMakeLists.txt index efdb7e83c..c171ed849 100644 --- a/Examples/Graph/CMakeLists.txt +++ b/Examples/Graph/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} Graph.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/LaparoscopicToolController/CMakeLists.txt b/Examples/LaparoscopicToolController/CMakeLists.txt index e56c2d528..e476884ff 100644 --- a/Examples/LaparoscopicToolController/CMakeLists.txt +++ b/Examples/LaparoscopicToolController/CMakeLists.txt @@ -28,6 +28,12 @@ if(iMSTK_USE_OMNI) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + + #----------------------------------------------------------------------------- + # Add shaders + #----------------------------------------------------------------------------- + include(imstkCopyAndCompileShaders) + CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/MeshIO/CMakeLists.txt b/Examples/MeshIO/CMakeLists.txt index 07b89a1d8..55638e0f2 100644 --- a/Examples/MeshIO/CMakeLists.txt +++ b/Examples/MeshIO/CMakeLists.txt @@ -27,7 +27,13 @@ add_executable(${PROJECT_NAME} MeshIO.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) - + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() + #----------------------------------------------------------------------------- # Associate external data #----------------------------------------------------------------------------- diff --git a/Examples/MshVegaIO/CMakeLists.txt b/Examples/MshVegaIO/CMakeLists.txt index 3370956d2..50938df29 100644 --- a/Examples/MshVegaIO/CMakeLists.txt +++ b/Examples/MshVegaIO/CMakeLists.txt @@ -28,6 +28,12 @@ add_executable(${PROJECT_NAME} MshVegaIO.cpp) #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() + #----------------------------------------------------------------------------- # Associate external data #----------------------------------------------------------------------------- diff --git a/Examples/ObjectController/CMakeLists.txt b/Examples/ObjectController/CMakeLists.txt index 766769a1a..8aa82c875 100644 --- a/Examples/ObjectController/CMakeLists.txt +++ b/Examples/ObjectController/CMakeLists.txt @@ -24,6 +24,12 @@ if(iMSTK_USE_OMNI) #----------------------------------------------------------------------------- add_executable(${PROJECT_NAME} ObjectController.cpp) + #----------------------------------------------------------------------------- + # Add shaders + #----------------------------------------------------------------------------- + include(imstkCopyAndCompileShaders) + CopyAndCompileShaders() + #----------------------------------------------------------------------------- # Link libraries to executable #----------------------------------------------------------------------------- diff --git a/Examples/PBDVolume/CMakeLists.txt b/Examples/PBDVolume/CMakeLists.txt index 916340e77..91affca8f 100644 --- a/Examples/PBDVolume/CMakeLists.txt +++ b/Examples/PBDVolume/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} PBDVolumeExample.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/Picking/CMakeLists.txt b/Examples/Picking/CMakeLists.txt index 40cfd32a7..6dd5fad3a 100644 --- a/Examples/Picking/CMakeLists.txt +++ b/Examples/Picking/CMakeLists.txt @@ -29,6 +29,12 @@ if(iMSTK_USE_OMNI) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + + #----------------------------------------------------------------------------- + # Add shaders + #----------------------------------------------------------------------------- + include(imstkCopyAndCompileShaders) + CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/Rendering/CMakeLists.txt b/Examples/Rendering/CMakeLists.txt index 194408c39..d4fec99a2 100644 --- a/Examples/Rendering/CMakeLists.txt +++ b/Examples/Rendering/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} Rendering.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/Screenshot/CMakeLists.txt b/Examples/Screenshot/CMakeLists.txt index 7eefe2a49..d1aa9bac2 100644 --- a/Examples/Screenshot/CMakeLists.txt +++ b/Examples/Screenshot/CMakeLists.txt @@ -22,6 +22,12 @@ project(Example-Screenshot) # Create executable #----------------------------------------------------------------------------- add_executable(${PROJECT_NAME} Screenshot.cpp) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Link libraries to executable diff --git a/Examples/Viewer/CMakeLists.txt b/Examples/Viewer/CMakeLists.txt index 8a7865210..474f5bdcd 100644 --- a/Examples/Viewer/CMakeLists.txt +++ b/Examples/Viewer/CMakeLists.txt @@ -22,6 +22,12 @@ project(Example-Viewer) # Create executable #----------------------------------------------------------------------------- add_executable(${PROJECT_NAME} Viewer.cpp) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Link libraries to executable diff --git a/Examples/VirtualCoupling/CMakeLists.txt b/Examples/VirtualCoupling/CMakeLists.txt index d24870ebe..a8da49200 100644 --- a/Examples/VirtualCoupling/CMakeLists.txt +++ b/Examples/VirtualCoupling/CMakeLists.txt @@ -23,6 +23,12 @@ if(iMSTK_USE_OMNI) # Create executable #----------------------------------------------------------------------------- add_executable(${PROJECT_NAME} VirtualCoupling.cpp) + + #----------------------------------------------------------------------------- + # Add shaders + #----------------------------------------------------------------------------- + include(imstkCopyAndCompileShaders) + CopyAndCompileShaders() #----------------------------------------------------------------------------- # Link libraries to executable diff --git a/Examples/VulkanDecals/CMakeLists.txt b/Examples/VulkanDecals/CMakeLists.txt index d1d62e8c0..86edb9e27 100644 --- a/Examples/VulkanDecals/CMakeLists.txt +++ b/Examples/VulkanDecals/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} VulkanDecals.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data diff --git a/Examples/continuousCollisionDetection/CMakeLists.txt b/Examples/continuousCollisionDetection/CMakeLists.txt index ec9ccc8c8..6a8b6ffbb 100644 --- a/Examples/continuousCollisionDetection/CMakeLists.txt +++ b/Examples/continuousCollisionDetection/CMakeLists.txt @@ -27,6 +27,12 @@ add_executable(${PROJECT_NAME} continuousCollisionDetection.cpp) # Link libraries to executable #----------------------------------------------------------------------------- target_link_libraries(${PROJECT_NAME} SimulationManager) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() #----------------------------------------------------------------------------- # Associate external data -- GitLab