Project
This commit is contained in:
Executable
+36
@@ -0,0 +1,36 @@
|
||||
option(SHADERS_DIR "Directory to look for SLANG shaders" "assets/shaders")
|
||||
|
||||
find_program(SLANGC_EXECUTABLE NAMES slangc)
|
||||
if(NOT SLANGC_EXECUTABLE)
|
||||
message(FATAL_ERROR "slangc executable not found.")
|
||||
else()
|
||||
message(STATUS "Found slangc executable: ${SLANGC_EXECUTABLE}")
|
||||
endif()
|
||||
|
||||
function(create_slang_shader_target TARGET SOURCE_DIR OUTPUT_DIR)
|
||||
file(MAKE_DIRECTORY ${OUTPUT_DIR})
|
||||
message(STATUS "Shader output directory: ${OUTPUT_DIR}")
|
||||
file(GLOB SHADER_FILES "${SOURCE_DIR}/*.slang")
|
||||
message(STATUS "Found shaders: ${SHADER_FILES}")
|
||||
set(ENTRY_POINTS -entry vertMain -entry fragMain)
|
||||
set(OUTPUT_FILES "")
|
||||
foreach(SHADER_FILE ${SHADER_FILES})
|
||||
get_filename_component(SHADER_NAME ${SHADER_FILE} NAME_WE)
|
||||
set(OUTPUT_FILE "${OUTPUT_DIR}/${SHADER_NAME}.spv")
|
||||
list(APPEND OUTPUT_FILES ${OUTPUT_FILE})
|
||||
message(STATUS "Compiling ${SHADER_FILE} to ${OUTPUT_FILE}")
|
||||
add_custom_command(
|
||||
OUTPUT ${OUTPUT_FILE}
|
||||
COMMAND ${SLANGC_EXECUTABLE} ${SHADER_FILE} -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name ${ENTRY_POINTS} -o ${OUTPUT_FILE}
|
||||
DEPENDS ${SHADER_FILE}
|
||||
COMMENT "Compiling ${SHADER_FILE} -> ${OUTPUT_FILE}"
|
||||
VERBATIM
|
||||
)
|
||||
endforeach()
|
||||
add_custom_target(${TARGET} ALL DEPENDS ${OUTPUT_FILES})
|
||||
endfunction()
|
||||
|
||||
create_slang_shader_target(slang_shaders
|
||||
"${SHADERS_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${SHADERS_DIR}"
|
||||
)
|
||||
Reference in New Issue
Block a user