• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright © 2021 Intel Corporation
2
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19# SOFTWARE.
20
21fs = import('fs')
22
23grl_lib_files = [
24  'gpu/libs/libraries.grl',
25]
26
27grl_grl_files = [
28  'gpu/build_leaf.grl',
29  'gpu/build_primref.grl',
30#  'gpu/build_refit.grl',
31  'gpu/copy.grl',
32#  'gpu/grl_api_interface_verify.grl',
33  'gpu/misc.grl',
34#  'gpu/morton_builder.grl',
35#  'gpu/msb_radix_bitonic_sort.grl',
36  'gpu/new_sah_builder.grl',
37  'gpu/postbuild_info.grl',
38#  'gpu/presplit.grl',
39#  'gpu/radix_sort.grl',
40#  'gpu/rebraid.grl',
41#  'gpu/traversal_shader.grl',
42]
43
44grl_lib_args = []
45foreach libfile : grl_lib_files
46  grl_lib_args += '--library'
47  grl_lib_args += files(libfile)
48endforeach
49
50grl_genX_files = [
51  'genX_grl_dispatch.c',
52  'genX_grl_uuid.cpp',
53]
54
55grl_lib_args = []
56foreach libfile : grl_lib_files
57  grl_lib_args += '--library'
58  grl_lib_args += files(libfile)
59endforeach
60
61grl_cl_kernel_h = custom_target(
62  'grl_cl_kernel.h',
63  input : ['grl_cl_kernel_gen.py', grl_grl_files, grl_lib_files],
64  output : 'grl_cl_kernel.h',
65  command : [
66    prog_python, '@INPUT0@', '--out-h', '@OUTPUT@',
67    grl_lib_args, files(grl_grl_files),
68  ],
69)
70
71has_ply = run_command(
72  prog_python, '-c',
73  '''
74import ply
75  ''', check : false)
76if has_ply.returncode() != 0
77  error('Python (3.x) ply module required to build GRL kernels.')
78endif
79
80r = run_command(prog_python, 'grl_cl_kernel_gen.py',
81                grl_lib_args, '--ls-kernels', grl_grl_files, check : false)
82assert(r.returncode() == 0, 'Failed to fetch GRL CL kernels')
83grl_kernels = r.stdout().strip().split()
84
85grl_metakernel_c = []
86grl_metakernel_h = []
87foreach grl_file : grl_grl_files
88  base_outfile = 'grl_metakernel_' + fs.replace_suffix(fs.name(grl_file), '')
89  outfiles = custom_target(
90    base_outfile,
91    input : ['grl_metakernel_gen.py', grl_file, grl_lib_files],
92    output : [base_outfile + '.h', base_outfile + '.c'],
93    command : [
94      prog_python, '@INPUT0@', '--out-h', '@OUTPUT0@',
95      '--out-c', '@OUTPUT1@', grl_lib_args, '@INPUT1@',
96    ],
97  )
98  grl_metakernel_h += outfiles[0]
99  grl_metakernel_c += outfiles[1]
100endforeach
101
102grl_genX_libs = []
103foreach t : [['125', 'gfx125', 'dg2']]
104  verX10 = t[0]
105  genX_prefix = t[1]
106  platform = t[2]
107
108  grl_compiled_cl_kernels = []
109  foreach k : grl_kernels
110    # get_cl_files dumps out filename:entrypoint:libfile1,libfile2,libfile3
111    cl_file = k.split(':')[0]
112    entrypoint = k.split(':')[1]
113    library_files = k.split(':')[2]
114    kernel_prefix = '_'.join([
115      genX_prefix,
116      fs.replace_suffix(cl_file, '').replace('gpu/', '').replace('/', '_'),
117      entrypoint
118    ])
119    input_args = [ files(cl_file), ]
120    if library_files != ''
121      foreach lib_file : library_files.split(',')
122        input_args += [ lib_file ]
123      endforeach
124    endif
125    prepended_input_args = []
126    foreach input_arg : input_args
127      prepended_input_args += ['--in', input_arg]
128    endforeach
129    outfile = kernel_prefix + '.h'
130    grl_compiled_cl_kernels += custom_target(
131      outfile,
132      input : cl_file,
133      output : outfile,
134      command : [
135        prog_intel_clc, '-p', platform, '--prefix', kernel_prefix,
136        '-e', entrypoint, prepended_input_args, '-o', '@OUTPUT@', '--',
137        '-cl-std=cl2.0', '-D__OPENCL_VERSION__=200',
138        '-DMAX_HW_SIMD_WIDTH=16', '-DMAX_WORKGROUP_SIZE=16',
139        '-I' + join_paths(meson.current_source_dir(), 'gpu'),
140        '-I' + join_paths(meson.current_source_dir(), 'include'),
141      ],
142      env: ['MESA_SHADER_CACHE_DISABLE=true',
143            'MESA_SPIRV_LOG_LEVEL=error'],
144      depends : dep_prog_intel_clc
145    )
146  endforeach
147
148  grl_cl_kernel_c = custom_target(
149    'grl_@0@_cl_kernel.c'.format(genX_prefix),
150    input : ['grl_cl_kernel_gen.py', grl_grl_files, grl_lib_files],
151    output : 'grl_@0@_cl_kernel.c'.format(genX_prefix),
152    command : [
153      prog_python, '@INPUT0@', '--out-c', '@OUTPUT@',
154      grl_lib_args, '--prefix', genX_prefix, files(grl_grl_files),
155    ],
156  )
157
158  grl_genX_libs += static_library(
159    'grl_@0@'.format(genX_prefix),
160    [grl_cl_kernel_h, grl_compiled_cl_kernels, grl_cl_kernel_c,
161     grl_genX_files, grl_metakernel_c, grl_metakernel_h],
162    include_directories : [
163      inc_include, inc_src,
164      inc_intel,
165    ],
166    c_args : [
167      no_override_init_args, sse2_args,
168      '-DGFX_VERx10=@0@'.format(verX10),
169    ],
170    cpp_args : [
171      sse2_args,
172      '-DGFX_VERx10=@0@'.format(verX10),
173    ],
174    dependencies : [
175      dep_valgrind, idep_nir_headers, idep_vulkan_util_headers, idep_vulkan_wsi_headers,
176      idep_vulkan_runtime_headers, idep_anv_headers, idep_genxml,
177    ],
178    gnu_symbol_visibility : 'hidden',
179  )
180endforeach
181
182libgrl_deps = [
183  dep_valgrind,
184  idep_nir_headers,
185  idep_vulkan_util_headers,
186  idep_vulkan_wsi_headers,
187]
188
189libgrl = static_library(
190  'grl',
191  [grl_cl_kernel_h],
192  include_directories : [
193    inc_include, inc_src, inc_intel,
194  ],
195  link_whole : [grl_genX_libs],
196  dependencies : [libgrl_deps, idep_anv_headers],
197)
198idep_grl = declare_dependency(
199  link_with : libgrl,
200  dependencies : libgrl_deps,
201  sources : [grl_metakernel_h, grl_cl_kernel_h],
202  include_directories : include_directories('include', 'gpu'),
203)
204