diff --git a/CMakeLists.txt b/CMakeLists.txt index 89c73f0..0f7a92a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,11 @@ find_package (Vulkan REQUIRED) find_package (PythonInterp 3 REQUIRED) find_package (glfw3 REQUIRED) +find_program (GLSLANG glslangValidator) +if (NOT GLSLANG) + message (FATAL_ERROR "could not locate glslangValidator") +endif () + ############################################################################### include_directories ("${CMAKE_CURRENT_BINARY_DIR}") @@ -86,6 +91,34 @@ add_library (cruft-vk STATIC ${sources}) target_link_libraries (cruft-vk cruft-util vulkan) +############################################################################### +list (APPEND shaders + tools/hello/shader.vert + tools/hello/shader.frag +) + +foreach (src ${shaders}) + set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + get_filename_component(ext ${src} EXT) + + get_filename_component(name ${src} DIRECTORY) + get_filename_component(name ${name} NAME) + + set(label "${name}${ext}.spv") + set(dst "${CMAKE_CURRENT_BINARY_DIR}/tools/${label}") + + add_custom_command( + OUTPUT ${dst} + COMMAND ${GLSLANG} -s -o ${dst} -V100 ${src} + DEPENDS ${src} + COMMENT "[glslang] ${label}" + VERBATIM + ) + + add_custom_target(${label} DEPENDS ${dst}) +endforeach () + + ############################################################################### get_directory_property (HAS_PARENT PARENT_DIRECTORY) if (HAS_PARENT) @@ -105,6 +138,11 @@ foreach (t info hello) target_link_libraries (vk_${t} cruft-vk glfw) endforeach () + +##----------------------------------------------------------------------------- +add_dependencies (vk_hello hello.vert.spv hello.frag.spv) + + ############################################################################### configure_file(libcruft-vk-system.pc.in libcruft-vk.pc) configure_file(Doxyfile.in Doxyfile) diff --git a/tools/hello.cpp b/tools/hello.cpp index b88fef9..93cbb83 100644 --- a/tools/hello.cpp +++ b/tools/hello.cpp @@ -288,8 +288,8 @@ main (void) auto graphics_queue = ldevice.queue (graphics_queue_id); auto present_queue = ldevice.queue (present_queue_id); - auto vert_module = create_shader (ldevice, "./hello/shader.vert"); - auto frag_module = create_shader (ldevice, "./hello/shader.frag"); + auto vert_module = create_shader (ldevice, "./hello.vert.spv"); + auto frag_module = create_shader (ldevice, "./hello.frag.spv"); VkBufferCreateInfo buffer_info {}; buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;