mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-25 00:09:02 +00:00
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>
This commit is contained in:
@@ -32,3 +32,5 @@ include_directories("../common/vulkan_wrapper")
|
|||||||
add_subdirectory(shaders)
|
add_subdirectory(shaders)
|
||||||
|
|
||||||
include(../CMakeCommon.txt)
|
include(../CMakeCommon.txt)
|
||||||
|
|
||||||
|
add_dependencies(${${MODULE_NAME}_OUT} vulkan_shaders)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
# CMP0007:NEW - Don't ignore empty elements in a list
|
|
||||||
cmake_policy(SET CMP0007 NEW)
|
|
||||||
find_program(
|
find_program(
|
||||||
Vulkan_glslang_binary
|
Vulkan_glslang_binary
|
||||||
NAMES glslang
|
NAMES glslang
|
||||||
@@ -10,40 +8,36 @@ if(${Vulkan_glslang_binary} STREQUAL "Vulkan_glslang_binary-NOTFOUND")
|
|||||||
else()
|
else()
|
||||||
message(STATUS "Found glslang: ${Vulkan_glslang_binary}")
|
message(STATUS "Found glslang: ${Vulkan_glslang_binary}")
|
||||||
|
|
||||||
set(IMAGE2D_SHADER_IN_FILE "image2D.comp")
|
set(vulkan_spirv_files "")
|
||||||
set(IMAGE2D_SHADER_TMP_OUT_FILE "tmp_image2D.comp")
|
|
||||||
set(BUFFER_SHADER_IN_FILE "buffer")
|
|
||||||
set(IMAGE2D_FORMATS_LIST_IN_FILE "image2D_test_formats.txt")
|
|
||||||
|
|
||||||
file(READ ${IMAGE2D_SHADER_IN_FILE} IMAGE2D_SHADER_UNFORMAT_CONTENT)
|
add_custom_command(
|
||||||
file(STRINGS ${IMAGE2D_FORMATS_LIST_IN_FILE} IMAGE2D_FORMATS_LIST)
|
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)
|
||||||
|
|
||||||
if(NOT DEFINED VULKAN_TEST_RESOURCES)
|
file(STRINGS "image2D_test_formats.txt" image2D_formats)
|
||||||
set(VULKAN_TEST_RESOURCES ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
foreach(IMAGE2D_FORMAT ${IMAGE2D_FORMATS_LIST})
|
foreach(format ${image2D_formats})
|
||||||
list(GET IMAGE2D_FORMAT 1 GLSL_FORMAT)
|
list(GET format 1 GLSL_FORMAT)
|
||||||
list(GET IMAGE2D_FORMAT 2 GLSL_TYPE_PREFIX)
|
list(GET format 2 GLSL_TYPE_PREFIX)
|
||||||
string(REPLACE "GLSL_FORMAT" "${GLSL_FORMAT}" IMAGE2D_SHADER_CONTENT "${IMAGE2D_SHADER_UNFORMAT_CONTENT}")
|
|
||||||
string(REPLACE "GLSL_TYPE_PREFIX" "${GLSL_TYPE_PREFIX}" IMAGE2D_SHADER_CONTENT "${IMAGE2D_SHADER_CONTENT}")
|
configure_file(image2D.comp.in image2D_${GLSL_FORMAT}.comp)
|
||||||
file(WRITE ${IMAGE2D_SHADER_TMP_OUT_FILE} "${IMAGE2D_SHADER_CONTENT}")
|
|
||||||
execute_process(
|
add_custom_command(
|
||||||
COMMAND ${Vulkan_glslang_binary} --target-env vulkan1.0 -o ${VULKAN_TEST_RESOURCES}/image2D_${GLSL_FORMAT}.spv ${IMAGE2D_SHADER_TMP_OUT_FILE}
|
OUTPUT image2D_${GLSL_FORMAT}.spv
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
COMMAND ${Vulkan_glslang_binary}
|
||||||
RESULT_VARIABLE commandStatus
|
--target-env vulkan1.0
|
||||||
OUTPUT_QUIET)
|
-o ${CMAKE_CURRENT_BINARY_DIR}/image2D_${GLSL_FORMAT}.spv
|
||||||
if(commandStatus AND NOT commandStatus EQUAL 0)
|
${CMAKE_CURRENT_BINARY_DIR}/image2D_${GLSL_FORMAT}.comp
|
||||||
message(FATAL_ERROR "shader -> spir-v compilation failed")
|
DEPENDS image2D_${GLSL_FORMAT}.comp
|
||||||
endif()
|
VERBATIM)
|
||||||
endforeach(IMAGE2D_FORMAT)
|
list(APPEND vulkan_spirv_files ${CMAKE_CURRENT_BINARY_DIR}/image2D_${GLSL_FORMAT}.spv)
|
||||||
execute_process(
|
endforeach()
|
||||||
COMMAND ${Vulkan_glslang_binary} --target-env vulkan1.0 -o ${VULKAN_TEST_RESOURCES}/${BUFFER_SHADER_IN_FILE}.spv ${BUFFER_SHADER_IN_FILE}.comp
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
add_custom_target(vulkan_shaders DEPENDS ${vulkan_spirv_files})
|
||||||
RESULT_VARIABLE commandStatus
|
|
||||||
OUTPUT_QUIET)
|
|
||||||
if(commandStatus AND NOT commandStatus EQUAL 0)
|
|
||||||
message(FATAL_ERROR "shader -> spir-v compilation failed")
|
|
||||||
endif()
|
|
||||||
file(REMOVE ${IMAGE2D_SHADER_TMP_OUT_FILE})
|
|
||||||
endif()
|
endif()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#version 450
|
#version 450
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
#extension GL_EXT_shader_explicit_arithmetic_types_int32 : enable
|
#extension GL_EXT_shader_explicit_arithmetic_types_int32 : enable
|
||||||
|
|
||||||
#define MAX_2D_IMAGES 5
|
#define MAX_2D_IMAGES 5
|
||||||
#define MAX_2D_IMAGE_MIP_LEVELS 11
|
#define MAX_2D_IMAGE_MIP_LEVELS 11
|
||||||
@@ -10,19 +10,25 @@ layout(binding = 0) buffer Params
|
|||||||
{
|
{
|
||||||
uint32_t numImage2DDescriptors;
|
uint32_t numImage2DDescriptors;
|
||||||
};
|
};
|
||||||
layout(binding = 1, GLSL_FORMAT ) uniform GLSL_TYPE_PREFIXimage2D image2DList[ MAX_2D_IMAGE_DESCRIPTORS ];
|
|
||||||
|
layout(binding = 1, ${GLSL_FORMAT}) uniform ${GLSL_TYPE_PREFIX}image2D image2DList[MAX_2D_IMAGE_DESCRIPTORS];
|
||||||
layout(local_size_x = 32, local_size_y = 32) in;
|
layout(local_size_x = 32, local_size_y = 32) in;
|
||||||
void main() {
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
uvec3 numThreads = gl_NumWorkGroups * gl_WorkGroupSize;
|
uvec3 numThreads = gl_NumWorkGroups * gl_WorkGroupSize;
|
||||||
for (uint32_t image2DIdx = 0; image2DIdx < numImage2DDescriptors; image2DIdx++) {
|
for (uint32_t image2DIdx = 0; image2DIdx < numImage2DDescriptors; image2DIdx++)
|
||||||
|
{
|
||||||
ivec2 imageDim = imageSize(image2DList[image2DIdx]);
|
ivec2 imageDim = imageSize(image2DList[image2DIdx]);
|
||||||
uint32_t heightBy2 = imageDim.y / 2;
|
uint32_t heightBy2 = imageDim.y / 2;
|
||||||
for (uint32_t row = gl_GlobalInvocationID.y; row < heightBy2; row += numThreads.y) {
|
for (uint32_t row = gl_GlobalInvocationID.y; row < heightBy2; row += numThreads.y)
|
||||||
for (uint32_t col = gl_GlobalInvocationID.x; col < imageDim.x; col += numThreads.x) {
|
{
|
||||||
|
for (uint32_t col = gl_GlobalInvocationID.x; col < imageDim.x; col += numThreads.x)
|
||||||
|
{
|
||||||
ivec2 coordsA = ivec2(col, row);
|
ivec2 coordsA = ivec2(col, row);
|
||||||
ivec2 coordsB = ivec2(col, imageDim.y - row - 1);
|
ivec2 coordsB = ivec2(col, imageDim.y - row - 1);
|
||||||
GLSL_TYPE_PREFIXvec4 dataA = imageLoad(image2DList[image2DIdx], coordsA);
|
${GLSL_TYPE_PREFIX}vec4 dataA = imageLoad(image2DList[image2DIdx], coordsA);
|
||||||
GLSL_TYPE_PREFIXvec4 dataB = imageLoad(image2DList[image2DIdx], coordsB);
|
${GLSL_TYPE_PREFIX}vec4 dataB = imageLoad(image2DList[image2DIdx], coordsB);
|
||||||
imageStore(image2DList[image2DIdx], coordsA, dataB);
|
imageStore(image2DList[image2DIdx], coordsA, dataB);
|
||||||
imageStore(image2DList[image2DIdx], coordsB, dataA);
|
imageStore(image2DList[image2DIdx], coordsB, dataA);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user