diff --git a/src/intel/vulkan/grl/genX_grl.h b/src/intel/vulkan/grl/genX_grl.h new file mode 100644 index 00000000000..82eaec5fa75 --- /dev/null +++ b/src/intel/vulkan/grl/genX_grl.h @@ -0,0 +1,47 @@ +/* + * Copyright © 2021 Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef ANV_GRL_H +#define ANV_GRL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "anv_private.h" +#include "grl/grl_cl_kernel.h" +#include "genxml/gen_macros.h" + +void +genX(grl_dispatch)(struct anv_cmd_buffer *cmd_buffer, + enum grl_cl_kernel kernel, + const uint32_t *global_size, + uint32_t arg_count, + const struct anv_kernel_arg *args); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* ANV_GRL_H */ diff --git a/src/intel/vulkan/grl/genX_grl_dispatch.c b/src/intel/vulkan/grl/genX_grl_dispatch.c new file mode 100644 index 00000000000..1ccc4c25594 --- /dev/null +++ b/src/intel/vulkan/grl/genX_grl_dispatch.c @@ -0,0 +1,89 @@ +/* + * Copyright © 2021 Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "genX_grl.h" + +static struct anv_shader_bin * +get_shader_bin(struct anv_device *device, + enum grl_cl_kernel kernel) +{ + const char *key = genX(grl_get_cl_kernel_sha1)(kernel); + int key_len = strlen(key); + + bool cache_hit = false; + struct anv_shader_bin *bin = + anv_device_search_for_kernel(device, device->internal_cache, + key, key_len, &cache_hit); + if (bin != NULL) + return bin; + + uint32_t dummy_param[32]; + struct brw_kernel kernel_data; + genX(grl_get_cl_kernel)(&kernel_data, kernel); + + assert(kernel_data.prog_data.base.nr_params <= ARRAY_SIZE(dummy_param)); + kernel_data.prog_data.base.param = dummy_param; + + struct anv_pipeline_bind_map bind_map = { + .kernel_args_size = kernel_data.args_size, + .kernel_arg_count = kernel_data.arg_count, + .kernel_args = (struct brw_kernel_arg_desc *)kernel_data.args, + }; + + bin = anv_device_upload_kernel(device, device->internal_cache, + MESA_SHADER_KERNEL, + key, key_len, + kernel_data.code, + kernel_data.prog_data.base.program_size, + &kernel_data.prog_data.base, + sizeof(kernel_data.prog_data), + NULL, 0, NULL, &bind_map); + + /* The cache already has a reference and it's not going anywhere so there + * is no need to hold a second reference. + */ + anv_shader_bin_unref(device, bin); + + return bin; +} + +void +genX(grl_dispatch)(struct anv_cmd_buffer *cmd_buffer, + enum grl_cl_kernel kernel, + const uint32_t *global_size, + uint32_t arg_count, + const struct anv_kernel_arg *args) +{ + struct anv_device *device = cmd_buffer->device; + + const struct intel_l3_weights w = + intel_get_default_l3_weights(device->info, true, true); + + struct anv_kernel ak = { + .bin = get_shader_bin(device, kernel), + .l3_config = intel_get_l3_config(device->info, w), + }; + + genX(cmd_buffer_dispatch_kernel)(cmd_buffer, &ak, global_size, + arg_count, args); +} diff --git a/src/intel/vulkan/grl/meson.build b/src/intel/vulkan/grl/meson.build index 502de39bfa2..268cf3a142f 100644 --- a/src/intel/vulkan/grl/meson.build +++ b/src/intel/vulkan/grl/meson.build @@ -47,6 +47,10 @@ foreach libfile : grl_lib_files grl_lib_args += files(libfile) endforeach +grl_genX_files = [ + 'genX_grl_dispatch.c', +] + grl_cl_kernel_h = custom_target( 'grl_cl_kernel.h', input : ['grl_cl_kernel_gen.py', grl_grl_files, grl_lib_files], @@ -114,17 +118,19 @@ foreach t : [['125', 'gfx125', 'dg2']] grl_genX_libs += static_library( 'grl_@0@'.format(genX_prefix), - [grl_cl_kernel_h, grl_compiled_cl_kernels, grl_cl_kernel_c], + [grl_cl_kernel_h, grl_compiled_cl_kernels, grl_cl_kernel_c, + grl_genX_files], include_directories : [ inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_compiler, - inc_intel, + inc_intel, inc_anv, ], c_args : [ no_override_init_args, c_sse2_args, '-DGFX_VERx10=@0@'.format(verX10), ], dependencies : [ - dep_valgrind, idep_nir_headers, idep_vulkan_util_headers, idep_vulkan_wsi_headers + dep_valgrind, idep_nir_headers, idep_vulkan_util_headers, idep_vulkan_wsi_headers, + idep_vulkan_runtime_headers, ], gnu_symbol_visibility : 'hidden', ) diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build index 64dad7eeef2..90a2dda0b5c 100644 --- a/src/intel/vulkan/meson.build +++ b/src/intel/vulkan/meson.build @@ -18,6 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +inc_anv = include_directories('.') subdir('grl')