Files
OpenCL-CTS/test_conformance/vulkan/shaders/CMakeLists.txt
Ahmed Hesham 4486241540 Generate the Vulkan shaders at build time (#2199)
Use `add_custom_command` and `add_custom_target` instead of
`execute_process` so the generation of the Vulkan shader is done at
build time and not configuration time.

Use `configure_file` instead of string replacement.

Fixes #2179

Signed-off-by: Ahmed Hesham <ahmed.hesham@arm.com>
2025-01-07 09:30:27 -08:00

44 lines
1.5 KiB
CMake

find_program(
Vulkan_glslang_binary
NAMES glslang
HINTS $ENV{VULKAN_SDK})
if(${Vulkan_glslang_binary} STREQUAL "Vulkan_glslang_binary-NOTFOUND")
message(FATAL_ERROR "glslang tool (part of Vulkan SDK) is a prerequisite to compile shaders to spir-v")
else()
message(STATUS "Found glslang: ${Vulkan_glslang_binary}")
set(vulkan_spirv_files "")
add_custom_command(
OUTPUT buffer.spv
COMMAND ${Vulkan_glslang_binary}
--target-env vulkan1.0
-o ${CMAKE_CURRENT_BINARY_DIR}/buffer.spv
${CMAKE_CURRENT_SOURCE_DIR}/buffer.comp
DEPENDS buffer.comp
VERBATIM)
list(APPEND vulkan_spirv_files ${CMAKE_CURRENT_BINARY_DIR}/buffer.spv)
file(STRINGS "image2D_test_formats.txt" image2D_formats)
foreach(format ${image2D_formats})
list(GET format 1 GLSL_FORMAT)
list(GET format 2 GLSL_TYPE_PREFIX)
configure_file(image2D.comp.in image2D_${GLSL_FORMAT}.comp)
add_custom_command(
OUTPUT image2D_${GLSL_FORMAT}.spv
COMMAND ${Vulkan_glslang_binary}
--target-env vulkan1.0
-o ${CMAKE_CURRENT_BINARY_DIR}/image2D_${GLSL_FORMAT}.spv
${CMAKE_CURRENT_BINARY_DIR}/image2D_${GLSL_FORMAT}.comp
DEPENDS image2D_${GLSL_FORMAT}.comp
VERBATIM)
list(APPEND vulkan_spirv_files ${CMAKE_CURRENT_BINARY_DIR}/image2D_${GLSL_FORMAT}.spv)
endforeach()
add_custom_target(vulkan_shaders DEPENDS ${vulkan_spirv_files})
endif()