| # Copyright 2019 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| import("../gn/build_rules.gni") | |
| import("../gn/glsl_shader_rules.gni") | |
| if (is_fuchsia) { | |
| import("//src/lib/vulkan/image_pipe_swapchain.gni") | |
| } | |
| # Helper template to define a test program that Vulkan through vk_app_state.h | |
| # Variables: | |
| # Anything that graphics_compute_vulkan_executable supports, and: | |
| # | |
| # glsl_shaders: Optional list of GLSL shader files that will be compiled | |
| # into SPIR-V modules automatically. | |
| # | |
| # glsl_shaders_c_header_name: If |glsl_shaders| is provided, name of a | |
| # generated C header that will contain the content of all generated | |
| # shaders as literal C arrays of uint32_t items. | |
| # | |
| template("vulkan_test_app") { | |
| if (defined(invoker.glsl_shaders)) { | |
| assert(defined(invoker.glsl_shaders_c_header_name)) | |
| _shaders_target = "compile_glsl_shaders_${target_name}" | |
| _shaders_output_dir = "${target_gen_dir}/${target_name}_shaders" | |
| # Compile the shaders to .spv | |
| graphics_compute_compile_glsl_shader_foreach(_shaders_target) { | |
| sources = invoker.glsl_shaders | |
| output_dir = _shaders_output_dir | |
| args = [ | |
| "--target-env", | |
| "vulkan1.1", | |
| ] | |
| } | |
| # Convert all .spv to a single C header. | |
| _shaders_c_source_target = "gen_shader_c_source_${target_name}" | |
| _shaders_c_source = | |
| "${_shaders_output_dir}/${invoker.glsl_shaders_c_header_name}" | |
| action(_shaders_c_source_target) { | |
| script = | |
| "${graphics_compute_dir}/scripts/convert_spirv_files_to_c_arrays.py" | |
| sources = get_target_outputs(":${_shaders_target}") | |
| outputs = [ _shaders_c_source ] | |
| args = [ | |
| "--output", | |
| rebase_path(outputs[0], root_build_dir), | |
| ] + rebase_path(sources, root_build_dir) | |
| deps = [ ":${_shaders_target}" ] | |
| } | |
| } | |
| graphics_compute_vulkan_executable(target_name) { | |
| testonly = true | |
| forward_variables_from(invoker, | |
| "*", | |
| [ | |
| "glsl_shaders", | |
| "glsl_shaders_c_header_name", | |
| ]) | |
| if (!defined(deps)) { | |
| deps = [] | |
| } | |
| deps += [ | |
| "${graphics_compute_dir}/tests:common", | |
| "${graphics_compute_dir}/tests:common_vk", | |
| ] | |
| if (defined(_shaders_c_source_target)) { | |
| if (!defined(include_dirs)) { | |
| include_dirs = [] | |
| } | |
| include_dirs += [ _shaders_output_dir ] | |
| deps += [ ":${_shaders_c_source_target}" ] | |
| } | |
| } | |
| } |