forked from NVIDIA/Q2RTX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompileShaders.cmake
87 lines (75 loc) · 3.55 KB
/
compileShaders.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
set(SHADER_SOURCE_DEPENDENCIES
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/asvgf.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/brdf.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/constants.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/global_textures.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/global_ubo.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/god_rays_shared.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/light_lists.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/path_tracer_rgen.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/path_tracer.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/precomputed_sky.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/precomputed_sky_params.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/projection.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/read_visbuf.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/sky.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/tiny_encryption_algorithm.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/tone_mapping_utils.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/utils.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/vertex_buffer.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/water.glsl)
find_program(GLSLANG_COMPILER
glslangValidator
PATHS
$ENV{VULKAN_SDK}/bin/
)
message(STATUS "Glslang compiler : ${GLSLANG_COMPILER}")
function(compile_shader)
set(options "")
set(oneValueArgs SOURCE_FILE OUTPUT_FILE_LIST)
set(multiValueArgs "")
cmake_parse_arguments(params "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT params_SOURCE_FILE)
message(FATAL_ERROR "compile_shader: SOURCE_FILE argument missing")
endif()
if (NOT params_OUTPUT_FILE_LIST)
message(FATAL_ERROR "compile_shader: OUTPUT_FILE_LIST argument missing")
endif()
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${params_SOURCE_FILE}")
get_filename_component(base_file_name ${src_file} NAME)
get_filename_component(file_extension ${src_file} EXT)
if (file_extension STREQUAL ".comp")
set(DEFINES "-DSHADER_STAGE_COMP")
elseif(file_extension STREQUAL ".rahit")
set(DEFINES "-DSHADER_STAGE_ACHIT")
elseif(file_extension STREQUAL ".rmiss")
set(DEFINES "-DSHADER_STAGE_RMISS")
elseif(file_extension STREQUAL ".rchit")
set(DEFINES "-DSHADER_STAGE_RCHIT")
elseif(file_extension STREQUAL ".rgen")
set(DEFINES "-DSHADER_STAGE_RGEN")
elseif(file_extension STREQUAL ".frag")
set(DEFINES "-DSHADER_STAGE_FRAG")
elseif(file_extension STREQUAL ".vert")
set(DEFINES "-DSHADER_STAGE_VERT")
else()
message(FATAL_ERROR "unknown extension in shader source file: ${file_extension}")
endif()
set_source_files_properties(${src_file} PROPERTIES VS_TOOL_OVERRIDE "None")
set (out_dir "${CMAKE_SOURCE_DIR}/baseq2/shader_vkpt")
set (out_file "${out_dir}/${base_file_name}.spv")
set(glslang_command_line
--target-env vulkan1.1
-DVKPT_SHADER
-V
${DEFINES}
"${src_file}"
-o "${out_file}")
add_custom_command(OUTPUT ${out_file}
DEPENDS ${src_file}
DEPENDS ${SHADER_SOURCE_DEPENDENCIES}
MAIN_DEPENDENCY ${src_file}
COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir}
COMMAND ${GLSLANG_COMPILER} ${glslang_command_line})
set(${params_OUTPUT_FILE_LIST} ${${params_OUTPUT_FILE_LIST}} ${out_file} PARENT_SCOPE)
endfunction()