CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. project(vk_sample)
  2. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  3. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin/VK/)
  4. find_program(Vulkan_NIS_GLSLC_EXECUTABLE
  5. NAMES glslc
  6. HINTS
  7. "$ENV{VULKAN_SDK}/bin"
  8. )
  9. find_program(Vulkan_NIS_DXC_EXECUTABLE
  10. NAMES dxc
  11. HINTS
  12. "$ENV{VULKAN_SDK}/bin"
  13. )
  14. set(IMGUI_SRC "${IMGUI_PATH}/backends/imgui_impl_vulkan.cpp"
  15. "${IMGUI_PATH}/backends/imgui_impl_glfw.cpp"
  16. "${IMGUI_PATH}/imgui.cpp"
  17. "${IMGUI_PATH}/imgui_demo.cpp"
  18. "${IMGUI_PATH}/imgui_draw.cpp"
  19. "${IMGUI_PATH}/imgui_tables.cpp"
  20. "${IMGUI_PATH}/imgui_widgets.cpp"
  21. )
  22. set(TINYEXR_PATH "${CMAKE_SOURCE_DIR}/third_party/tinyexr/")
  23. set(TINYEXR_INCLUDE "${TINYEXR_PATH}" "${TINYEXR_PATH}/deps/miniz")
  24. set(TINYEXR_SRC "${TINYEXR_PATH}/deps/miniz/miniz.c")
  25. set(STB_PATH "${CMAKE_SOURCE_DIR}/third_party/stb/")
  26. set(STB_INCLUDE "${STB_PATH}")
  27. set(SAMPLE_SRC "src/AppRenderer.cpp"
  28. "src/DeviceResources.cpp"
  29. "src/NVScaler.cpp"
  30. "src/NVSharpen.cpp"
  31. "src/Sample.cpp"
  32. "${COMMON_PATH}/Image.cpp"
  33. "src/UIRenderer.cpp"
  34. )
  35. set(SAMPLE_HEADERS "include/AppRenderer.h"
  36. "include/DeviceResources.h"
  37. "include/NVScaler.h"
  38. "include/NVSharpen.h"
  39. "include/UIRenderer.h"
  40. "include/VKUtilities.h"
  41. "${COMMON_PATH}/Utilities.h"
  42. )
  43. add_definitions(-DNIS_VK_SAMPLE -DNIS_DXC)
  44. source_group("external" FILES ${IMGUI_SRC} ${TINYEXR_SRC})
  45. source_group("shaders" FILES ${SAMPLE_SHADERS})
  46. add_executable(${PROJECT_NAME} ${SAMPLE_SRC} ${IMGUI_SRC} ${TINYEXR_SRC} ${SAMPLE_HEADERS} ${SPIRV_BLOB_SCALER}
  47. ${SPIRV_BLOB_SHARPEN} ${SPIRV_BLOB_SCALER_GLSL} ${SPIRV_BLOB_SHARPEN_GLSL})
  48. target_include_directories (${PROJECT_NAME} PUBLIC include ${IMGUI_INCLUDE} ${TINYEXR_INCLUDE} ${STB_INCLUDE} ${COMMON_PATH} ${NIS_PATH})
  49. target_link_libraries(${PROJECT_NAME} LINK_PUBLIC glfw Vulkan::Vulkan)
  50. set(SAMPLE_SHADERS "${NIS_PATH}/NIS_Main.hlsl")
  51. set(DXC_ARGS_HLSL -spirv -T cs_6_2 -D NIS_DXC=1 -DNIS_USE_HALF_PRECISION=1 -D NIS_BLOCK_WIDTH=32 -D NIS_THREAD_GROUP_SIZE=256)
  52. set(SPIRV_BLOB_SCALER "nis_scaler.spv")
  53. add_custom_command(
  54. TARGET ${PROJECT_NAME} POST_BUILD
  55. # OUTPUT ${SPIRV_BLOB_SCALER}
  56. COMMAND ${Vulkan_NIS_DXC_EXECUTABLE} -D NIS_SCALER=1 -D NIS_BLOCK_HEIGHT=24 ${DXC_ARGS_HLSL} -Fo ${SPIRV_BLOB_SCALER} ${SAMPLE_SHADERS}
  57. DEPENDS ${SAMPLE_SHADERS}
  58. )
  59. set(SPIRV_BLOB_SHARPEN "nis_sharpen.spv")
  60. add_custom_command(
  61. TARGET ${PROJECT_NAME} POST_BUILD
  62. # OUTPUT ${SPIRV_BLOB_SHARPEN}
  63. COMMAND ${Vulkan_NIS_DXC_EXECUTABLE} -D NIS_SCALER=0 -D NIS_BLOCK_HEIGHT=32 ${DXC_ARGS_HLSL} -Fo ${SPIRV_BLOB_SHARPEN} ${SAMPLE_SHADERS}
  64. DEPENDS ${SAMPLE_SHADERS}
  65. )
  66. set(SAMPLE_SHADERS_GLSL "${NIS_PATH}/NIS_Main.glsl")
  67. set(SPIRV_BLOB_SCALER_GLSL "nis_scaler_glsl.spv")
  68. set(GLSLC_ARGS -x glsl -DNIS_BLOCK_WIDTH=32 -DNIS_THREAD_GROUP_SIZE=256 -DNIS_USE_HALF_PRECISION=1 -DNIS_GLSL=1 -fshader-stage=comp)
  69. add_custom_command(
  70. TARGET ${PROJECT_NAME} POST_BUILD
  71. # OUTPUT ${SPIRV_BLOB_SCALER_GLSL}
  72. COMMAND ${Vulkan_NIS_GLSLC_EXECUTABLE} -DNIS_SCALER=1 -DNIS_BLOCK_HEIGHT=24 ${GLSLC_ARGS} -o ${SPIRV_BLOB_SCALER_GLSL} ${SAMPLE_SHADERS_GLSL}
  73. DEPENDS ${SAMPLE_SHADERS_GLSL}
  74. )
  75. set(SPIRV_BLOB_SHARPEN_GLSL "nis_sharpen_glsl.spv")
  76. add_custom_command(
  77. TARGET ${PROJECT_NAME} POST_BUILD
  78. # OUTPUT ${SPIRV_BLOB_SHARPEN_GLSL}
  79. COMMAND ${Vulkan_NIS_GLSLC_EXECUTABLE} -DNIS_SCALER=0 -DNIS_BLOCK_HEIGHT=32 ${GLSLC_ARGS} -o ${SPIRV_BLOB_SHARPEN_GLSL} ${SAMPLE_SHADERS_GLSL}
  80. DEPENDS ${SAMPLE_SHADERS_GLSL}
  81. )
  82. add_custom_command(
  83. TARGET ${PROJECT_NAME} POST_BUILD
  84. COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/NIS
  85. COMMAND ${CMAKE_COMMAND} -E copy_directory ${NIS_PATH} $<TARGET_FILE_DIR:${PROJECT_NAME}>/NIS
  86. COMMAND ${CMAKE_COMMAND} -E copy_if_different "nis_scaler.spv" $<TARGET_FILE_DIR:${PROJECT_NAME}>/NIS
  87. COMMAND ${CMAKE_COMMAND} -E copy_if_different "nis_sharpen.spv" $<TARGET_FILE_DIR:${PROJECT_NAME}>/NIS
  88. COMMAND ${CMAKE_COMMAND} -E copy_if_different "nis_scaler_glsl.spv" $<TARGET_FILE_DIR:${PROJECT_NAME}>/NIS
  89. COMMAND ${CMAKE_COMMAND} -E copy_if_different "nis_sharpen_glsl.spv" $<TARGET_FILE_DIR:${PROJECT_NAME}>/NIS
  90. )
  91. add_custom_command(
  92. TARGET ${PROJECT_NAME} POST_BUILD
  93. COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/media/images
  94. COMMAND ${CMAKE_COMMAND} -E copy_directory ${SAMPLES_PATH}/media/images $<TARGET_FILE_DIR:${PROJECT_NAME}>/media/images
  95. )