From 46644ba371e817d8f33ad7b46ce2ba7775e6d2cc Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 21 Mar 2024 11:47:59 -0700 Subject: [PATCH] meson: use glslang --depfile argument when possible This reduces the amount of manual dependency tracking developers need to do. This is turned on if glslang >= 11.3.0 is used, or 11.9.0 on Windows, but otherwise the status quo is maintained. This means I have not removed any use of `depend_files`. We could make make these hard requirements and remove the use of `depend_files` too. Part-of: --- meson.build | 16 +++++++++++++++- src/amd/compiler/tests/glsl_scraper.py | 5 +++++ src/amd/compiler/tests/meson.build | 14 ++++++++++---- src/amd/vulkan/bvh/meson.build | 10 ++++++---- src/amd/vulkan/radix_sort/shaders/meson.build | 14 ++++++++++---- src/intel/shaders/meson.build | 4 +++- src/util/glsl2spirv.py | 12 ++++++++++++ src/vulkan/overlay-layer/meson.build | 12 ++++++++++-- src/vulkan/runtime/meson.build | 6 +++++- 9 files changed, 76 insertions(+), 17 deletions(-) diff --git a/meson.build b/meson.build index 072dd7bcb21..063c5d3adff 100644 --- a/meson.build +++ b/meson.build @@ -623,8 +623,22 @@ if vdpau_drivers_path == '' vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau') endif -prog_glslang = find_program('glslangValidator', native : true, required : with_vulkan_overlay_layer or with_aco_tests or with_amd_vk or with_intel_vk) +# GLSL has interesting version output and Meson doesn't parse it correctly as of +# Meson 1.4.0 +prog_glslang = find_program('glslangValidator', native : true, + required : with_vulkan_overlay_layer or with_aco_tests or with_amd_vk or with_intel_vk) if prog_glslang.found() + # Check if glslang has depfile support. Support was added in 11.3.0, but + # Windows path support was broken until 11.9.0. + # + # It is intentional to check the build machine, since we need to ensure that + # glslang will output valid paths on the build platform + _glslang_check = build_machine.system() == 'windows' ? '>= 11.9.0' : '>= 11.3.0' + if run_command(prog_glslang, ['--version'], check : false).stdout().split(':')[2].version_compare(_glslang_check) + glslang_depfile = ['--depfile', '@DEPFILE@'] + else + glslang_depfile = [] + endif if run_command(prog_glslang, [ '--quiet', '--version' ], check : false).returncode() == 0 glslang_quiet = ['--quiet'] else diff --git a/src/amd/compiler/tests/glsl_scraper.py b/src/amd/compiler/tests/glsl_scraper.py index 3167d7cf614..480a99e93ea 100644 --- a/src/amd/compiler/tests/glsl_scraper.py +++ b/src/amd/compiler/tests/glsl_scraper.py @@ -91,6 +91,8 @@ class Shader: if self.target_env: args += ['--target-env', self.target_env] args += ['-o', out_file.name, in_file.name] + if depfile is not None: + args.extend(['--depfile', depfile]) with subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE, @@ -300,6 +302,8 @@ def parse_args(): default='glslangValidator', dest='glslang', help='Full path to the glslangValidator shader compiler.') + p.add_argument('--depfile', metavar='DEPFILE', default=None, action="store", + help="Where to have glslang write a depfile") p.add_argument('infile', metavar='INFILE') return p.parse_args() @@ -309,6 +313,7 @@ args = parse_args() infname = args.infile outfname = args.outfile glslang = args.glslang +depfile = args.depfile with open_file(infname, 'r') as infile: parser = Parser(infile) diff --git a/src/amd/compiler/tests/meson.build b/src/amd/compiler/tests/meson.build index f87edd5c6b8..5a19fba41dd 100644 --- a/src/amd/compiler/tests/meson.build +++ b/src/amd/compiler/tests/meson.build @@ -30,10 +30,16 @@ spirv_files = files( 'test_d3d11_derivs.cpp', ) -gen_spirv = generator(prog_python, - output : '@BASENAME@-spirv.h', - arguments : [join_paths(meson.current_source_dir(), 'glsl_scraper.py'), - '@INPUT@', '--with-glslang', prog_glslang.full_path(), '-o', '@OUTPUT@']) +gen_spirv = generator( + prog_python, + output : '@BASENAME@-spirv.h', + arguments : [ + join_paths(meson.current_source_dir(), 'glsl_scraper.py'), + '@INPUT@', '--with-glslang', prog_glslang.full_path(), '-o', '@OUTPUT@', + glslang_depfile, + ], + depfile: '@BASENAME@-spriv.h.d', +) gen_spirv_files = gen_spirv.process(spirv_files) test( diff --git a/src/amd/vulkan/bvh/meson.build b/src/amd/vulkan/bvh/meson.build index 4f35488aea3..7b70d0b1fb1 100644 --- a/src/amd/vulkan/bvh/meson.build +++ b/src/amd/vulkan/bvh/meson.build @@ -72,19 +72,21 @@ bvh_includes = files( bvh_spv = [] foreach s : bvh_shaders command = [ - prog_glslang, '-V', '-I' + bvh_include_dir, '--target-env', 'spirv1.5', '-x', '-o', '@OUTPUT@', '@INPUT@' + prog_glslang, '-V', '-I' + bvh_include_dir, '--target-env', 'spirv1.5', + '-x', '-o', '@OUTPUT@', '@INPUT@', glslang_depfile, glslang_quiet, ] - command += glslang_quiet foreach define : s[2] command += '-D' + define endforeach + _bvh_name = '@0@.spv.h'.format(s[1]) bvh_spv += custom_target( - s[1] + '.spv.h', + _bvh_name, input : s[0], - output : s[1] + '.spv.h', + output : _bvh_name, command : command, + depfile : f'@_bvh_name@.d', depend_files: bvh_includes ) endforeach diff --git a/src/amd/vulkan/radix_sort/shaders/meson.build b/src/amd/vulkan/radix_sort/shaders/meson.build index edba4b1a79a..0c1e2e282d9 100644 --- a/src/amd/vulkan/radix_sort/shaders/meson.build +++ b/src/amd/vulkan/radix_sort/shaders/meson.build @@ -26,10 +26,16 @@ shader_include_files = files( radix_sort_spv = [] foreach s : radix_sort_shaders + _name = f'@s@.spv.h' radix_sort_spv += custom_target( - s + '.spv.h', + _name, input : s, - output : s + '.spv.h', - command : [prog_glslang, '-V', '-I' + shader_include_dir, '--target-env', 'spirv1.3', '-x', '-o', '@OUTPUT@', '@INPUT@'] + glslang_quiet, - depend_files: shader_include_files) + output : _name, + command : [ + prog_glslang, '-V', '-I' + shader_include_dir, '--target-env', 'spirv1.3', + '-x', '-o', '@OUTPUT@', '@INPUT@', glslang_quiet, glslang_depfile, + ], + depfile : f'@_name@.d', + depend_files : shader_include_files, + ) endforeach diff --git a/src/intel/shaders/meson.build b/src/intel/shaders/meson.build index e8e2c311324..ad064df3fdb 100644 --- a/src/intel/shaders/meson.build +++ b/src/intel/shaders/meson.build @@ -13,7 +13,9 @@ if with_intel_vk '--vn', 'float64_spv_source', '--glsl-version', '450', '-Olib', - ] + glslang_depfile, + ], + depfile : 'float64_spv.h.d', ) endif diff --git a/src/util/glsl2spirv.py b/src/util/glsl2spirv.py index 5e2198a3f74..7238fb3b649 100644 --- a/src/util/glsl2spirv.py +++ b/src/util/glsl2spirv.py @@ -38,6 +38,9 @@ if T.TYPE_CHECKING: extra: T.Optional[str] vn: str stage: str + includes: T.List[str] + defines: T.List[str] + depfile: T.Optional[str] def get_args() -> 'Arguments': @@ -84,6 +87,12 @@ def get_args() -> 'Arguments': default=[], action='append', help="Defines") + + parser.add_argument('--depfile', + dest="depfile", + default=None, + action='store', + help='Where glslangValidator should write its depfile, if unset no depfile will be written.') args = parser.parse_args() return args @@ -170,6 +179,9 @@ def process_file(args: 'Arguments') -> None: if args.create_entry is not None: cmd_list.extend(["--entry-point", args.create_entry]) + if args.depfile is not None: + cmd_list.extend(['--depfile', args.depfile]) + for f in args.includes: cmd_list.append('-I' + f) diff --git a/src/vulkan/overlay-layer/meson.build b/src/vulkan/overlay-layer/meson.build index 8a01300bd37..cb77fd2651f 100644 --- a/src/vulkan/overlay-layer/meson.build +++ b/src/vulkan/overlay-layer/meson.build @@ -24,9 +24,17 @@ overlay_shaders = [ ] overlay_spv = [] foreach s : ['overlay.frag', 'overlay.vert'] + _name = f'@s@.spv.h' overlay_spv += custom_target( - s + '.spv.h', input : s, output : s + '.spv.h', - command : [prog_glslang, '-V', '-x', '-o', '@OUTPUT@', '@INPUT@'] + glslang_quiet) + _name, + input : s, + output : _name, + command : [ + prog_glslang, '-V', '-x', '-o', '@OUTPUT@', '@INPUT@', glslang_quiet, + glslang_depfile, + ], + depfile : f'@_name@.d', + ) endforeach vklayer_files = files( diff --git a/src/vulkan/runtime/meson.build b/src/vulkan/runtime/meson.build index 400d023af33..ff2dea13145 100644 --- a/src/vulkan/runtime/meson.build +++ b/src/vulkan/runtime/meson.build @@ -295,7 +295,11 @@ if prog_glslang.found() 'astc_spv.h', input : astc_decoder_glsl_file, output : 'astc_spv.h', - command : [prog_glslang, '-V', '-S', 'comp', '-x', '-o', '@OUTPUT@', '@INPUT@'] + glslang_quiet, + command : [ + prog_glslang, '-V', '-S', 'comp', '-x', '-o', '@OUTPUT@', '@INPUT@', + glslang_quiet, glslang_depfile, + ], + depfile : 'astc_spv.h.d', ) endif