From 91abb0e0afe433dda376fb2d232a647d2fa928f1 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 4 Sep 2025 17:51:08 +0300 Subject: [PATCH] anv: move internal RT shaders around anv_pipeline.c is about to go. Signed-off-by: Lionel Landwerlin Reviewed-by: Caio Oliveira Part-of: --- src/intel/vulkan/anv_pipeline.c | 199 ------------------------------- src/intel/vulkan/anv_util.c | 201 ++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 199 deletions(-) diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 2d15b1616c0..9364eb4b909 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -3884,205 +3884,6 @@ anv_pipeline_compile_ray_tracing(struct anv_ray_tracing_pipeline *pipeline, return VK_SUCCESS; } -VkResult -anv_device_init_rt_shaders(struct anv_device *device) -{ - if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline) - return VK_SUCCESS; - - bool cache_hit; - - struct anv_push_descriptor_info empty_push_desc_info = {}; - struct anv_pipeline_bind_map empty_bind_map = {}; - struct brw_rt_trampoline { - char name[16]; - struct brw_cs_prog_key key; - } trampoline_key = { - .name = "rt-trampoline", - }; - device->rt_trampoline = - anv_device_search_for_kernel(device, device->internal_cache, - &trampoline_key, sizeof(trampoline_key), - &cache_hit); - if (device->rt_trampoline == NULL) { - - void *tmp_ctx = ralloc_context(NULL); - nir_shader *trampoline_nir = - brw_nir_create_raygen_trampoline(device->physical->compiler, tmp_ctx); - - if (device->info->ver >= 20) - trampoline_nir->info.subgroup_size = SUBGROUP_SIZE_REQUIRE_16; - else - trampoline_nir->info.subgroup_size = SUBGROUP_SIZE_REQUIRE_8; - - struct brw_cs_prog_data trampoline_prog_data = { - .uses_btd_stack_ids = true, - }; - struct brw_compile_cs_params params = { - .base = { - .nir = trampoline_nir, - .log_data = device, - .mem_ctx = tmp_ctx, - }, - .key = &trampoline_key.key, - .prog_data = &trampoline_prog_data, - }; - const unsigned *tramp_data = - brw_compile_cs(device->physical->compiler, ¶ms); - - struct anv_shader_upload_params upload_params = { - .stage = MESA_SHADER_COMPUTE, - .key_data = &trampoline_key, - .key_size = sizeof(trampoline_key), - .kernel_data = tramp_data, - .kernel_size = trampoline_prog_data.base.program_size, - .prog_data = &trampoline_prog_data.base, - .prog_data_size = sizeof(trampoline_prog_data), - .bind_map = &empty_bind_map, - .push_desc_info = &empty_push_desc_info, - }; - - device->rt_trampoline = - anv_device_upload_kernel(device, device->internal_cache, - &upload_params); - - ralloc_free(tmp_ctx); - - if (device->rt_trampoline == NULL) - return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); - } - - /* 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, device->rt_trampoline); - - struct brw_rt_trivial_return { - char name[16]; - struct brw_bs_prog_key key; - } return_key = { - .name = "rt-trivial-ret", - }; - device->rt_trivial_return = - anv_device_search_for_kernel(device, device->internal_cache, - &return_key, sizeof(return_key), - &cache_hit); - if (device->rt_trivial_return == NULL) { - void *tmp_ctx = ralloc_context(NULL); - nir_shader *trivial_return_nir = - brw_nir_create_trivial_return_shader(device->physical->compiler, tmp_ctx); - - NIR_PASS(_, trivial_return_nir, brw_nir_lower_rt_intrinsics, - &return_key.key.base, device->info); - - struct brw_bs_prog_data return_prog_data = { 0, }; - struct brw_compile_bs_params params = { - .base = { - .nir = trivial_return_nir, - .log_data = device, - .mem_ctx = tmp_ctx, - }, - .key = &return_key.key, - .prog_data = &return_prog_data, - }; - const unsigned *return_data = - brw_compile_bs(device->physical->compiler, ¶ms); - - struct anv_shader_upload_params upload_params = { - .stage = MESA_SHADER_CALLABLE, - .key_data = &return_key, - .key_size = sizeof(return_key), - .kernel_data = return_data, - .kernel_size = return_prog_data.base.program_size, - .prog_data = &return_prog_data.base, - .prog_data_size = sizeof(return_prog_data), - .bind_map = &empty_bind_map, - .push_desc_info = &empty_push_desc_info, - }; - - device->rt_trivial_return = - anv_device_upload_kernel(device, device->internal_cache, - &upload_params); - - ralloc_free(tmp_ctx); - - if (device->rt_trivial_return == NULL) - return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); - } - - /* 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, device->rt_trivial_return); - - struct brw_rt_null_ahs { - char name[16]; - struct brw_bs_prog_key key; - } null_return_key = { - .name = "rt-null-ahs", - }; - device->rt_null_ahs = - anv_device_search_for_kernel(device, device->internal_cache, - &null_return_key, sizeof(null_return_key), - &cache_hit); - if (device->rt_null_ahs == NULL) { - void *tmp_ctx = ralloc_context(NULL); - nir_shader *null_ahs_nir = - brw_nir_create_null_ahs_shader(device->physical->compiler, tmp_ctx); - - NIR_PASS(_, null_ahs_nir, brw_nir_lower_rt_intrinsics, - &null_return_key.key.base, device->info); - - struct brw_bs_prog_data return_prog_data = { 0, }; - struct brw_compile_bs_params params = { - .base = { - .nir = null_ahs_nir, - .log_data = device, - .mem_ctx = tmp_ctx, - }, - .key = &null_return_key.key, - .prog_data = &return_prog_data, - }; - const unsigned *return_data = - brw_compile_bs(device->physical->compiler, ¶ms); - - struct anv_shader_upload_params upload_params = { - .stage = MESA_SHADER_CALLABLE, - .key_data = &null_return_key, - .key_size = sizeof(null_return_key), - .kernel_data = return_data, - .kernel_size = return_prog_data.base.program_size, - .prog_data = &return_prog_data.base, - .prog_data_size = sizeof(return_prog_data), - .bind_map = &empty_bind_map, - .push_desc_info = &empty_push_desc_info, - }; - - device->rt_null_ahs = - anv_device_upload_kernel(device, device->internal_cache, - &upload_params); - - ralloc_free(tmp_ctx); - - if (device->rt_null_ahs == NULL) - return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); - } - - /* 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, device->rt_null_ahs); - - return VK_SUCCESS; -} - -void -anv_device_finish_rt_shaders(struct anv_device *device) -{ - if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline) - return; -} - static void anv_ray_tracing_pipeline_init(struct anv_ray_tracing_pipeline *pipeline, struct anv_device *device, diff --git a/src/intel/vulkan/anv_util.c b/src/intel/vulkan/anv_util.c index d36ecd0a2b9..efe0d8909d3 100644 --- a/src/intel/vulkan/anv_util.c +++ b/src/intel/vulkan/anv_util.c @@ -33,6 +33,8 @@ #include "anv_private.h" #include "vk_enum_to_str.h" +#include "compiler/brw_nir_rt.h" + #ifdef NO_REGEX typedef int regex_t; #define REG_EXTENDED 0 @@ -331,3 +333,202 @@ void anv_wait_for_attach() { } } } + +VkResult +anv_device_init_rt_shaders(struct anv_device *device) +{ + if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline) + return VK_SUCCESS; + + bool cache_hit; + + struct anv_push_descriptor_info empty_push_desc_info = {}; + struct anv_pipeline_bind_map empty_bind_map = {}; + struct brw_rt_trampoline { + char name[16]; + struct brw_cs_prog_key key; + } trampoline_key = { + .name = "rt-trampoline", + }; + device->rt_trampoline = + anv_device_search_for_kernel(device, device->internal_cache, + &trampoline_key, sizeof(trampoline_key), + &cache_hit); + if (device->rt_trampoline == NULL) { + + void *tmp_ctx = ralloc_context(NULL); + nir_shader *trampoline_nir = + brw_nir_create_raygen_trampoline(device->physical->compiler, tmp_ctx); + + if (device->info->ver >= 20) + trampoline_nir->info.subgroup_size = SUBGROUP_SIZE_REQUIRE_16; + else + trampoline_nir->info.subgroup_size = SUBGROUP_SIZE_REQUIRE_8; + + struct brw_cs_prog_data trampoline_prog_data = { + .uses_btd_stack_ids = true, + }; + struct brw_compile_cs_params params = { + .base = { + .nir = trampoline_nir, + .log_data = device, + .mem_ctx = tmp_ctx, + }, + .key = &trampoline_key.key, + .prog_data = &trampoline_prog_data, + }; + const unsigned *tramp_data = + brw_compile_cs(device->physical->compiler, ¶ms); + + struct anv_shader_upload_params upload_params = { + .stage = MESA_SHADER_COMPUTE, + .key_data = &trampoline_key, + .key_size = sizeof(trampoline_key), + .kernel_data = tramp_data, + .kernel_size = trampoline_prog_data.base.program_size, + .prog_data = &trampoline_prog_data.base, + .prog_data_size = sizeof(trampoline_prog_data), + .bind_map = &empty_bind_map, + .push_desc_info = &empty_push_desc_info, + }; + + device->rt_trampoline = + anv_device_upload_kernel(device, device->internal_cache, + &upload_params); + + ralloc_free(tmp_ctx); + + if (device->rt_trampoline == NULL) + return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); + } + + /* 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, device->rt_trampoline); + + struct brw_rt_trivial_return { + char name[16]; + struct brw_bs_prog_key key; + } return_key = { + .name = "rt-trivial-ret", + }; + device->rt_trivial_return = + anv_device_search_for_kernel(device, device->internal_cache, + &return_key, sizeof(return_key), + &cache_hit); + if (device->rt_trivial_return == NULL) { + void *tmp_ctx = ralloc_context(NULL); + nir_shader *trivial_return_nir = + brw_nir_create_trivial_return_shader(device->physical->compiler, tmp_ctx); + + NIR_PASS(_, trivial_return_nir, brw_nir_lower_rt_intrinsics, + &return_key.key.base, device->info); + + struct brw_bs_prog_data return_prog_data = { 0, }; + struct brw_compile_bs_params params = { + .base = { + .nir = trivial_return_nir, + .log_data = device, + .mem_ctx = tmp_ctx, + }, + .key = &return_key.key, + .prog_data = &return_prog_data, + }; + const unsigned *return_data = + brw_compile_bs(device->physical->compiler, ¶ms); + + struct anv_shader_upload_params upload_params = { + .stage = MESA_SHADER_CALLABLE, + .key_data = &return_key, + .key_size = sizeof(return_key), + .kernel_data = return_data, + .kernel_size = return_prog_data.base.program_size, + .prog_data = &return_prog_data.base, + .prog_data_size = sizeof(return_prog_data), + .bind_map = &empty_bind_map, + .push_desc_info = &empty_push_desc_info, + }; + + device->rt_trivial_return = + anv_device_upload_kernel(device, device->internal_cache, + &upload_params); + + ralloc_free(tmp_ctx); + + if (device->rt_trivial_return == NULL) + return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); + } + + /* 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, device->rt_trivial_return); + + struct brw_rt_null_ahs { + char name[16]; + struct brw_bs_prog_key key; + } null_return_key = { + .name = "rt-null-ahs", + }; + device->rt_null_ahs = + anv_device_search_for_kernel(device, device->internal_cache, + &null_return_key, sizeof(null_return_key), + &cache_hit); + if (device->rt_null_ahs == NULL) { + void *tmp_ctx = ralloc_context(NULL); + nir_shader *null_ahs_nir = + brw_nir_create_null_ahs_shader(device->physical->compiler, tmp_ctx); + + NIR_PASS(_, null_ahs_nir, brw_nir_lower_rt_intrinsics, + &null_return_key.key.base, device->info); + + struct brw_bs_prog_data return_prog_data = { 0, }; + struct brw_compile_bs_params params = { + .base = { + .nir = null_ahs_nir, + .log_data = device, + .mem_ctx = tmp_ctx, + }, + .key = &null_return_key.key, + .prog_data = &return_prog_data, + }; + const unsigned *return_data = + brw_compile_bs(device->physical->compiler, ¶ms); + + struct anv_shader_upload_params upload_params = { + .stage = MESA_SHADER_CALLABLE, + .key_data = &null_return_key, + .key_size = sizeof(null_return_key), + .kernel_data = return_data, + .kernel_size = return_prog_data.base.program_size, + .prog_data = &return_prog_data.base, + .prog_data_size = sizeof(return_prog_data), + .bind_map = &empty_bind_map, + .push_desc_info = &empty_push_desc_info, + }; + + device->rt_null_ahs = + anv_device_upload_kernel(device, device->internal_cache, + &upload_params); + + ralloc_free(tmp_ctx); + + if (device->rt_null_ahs == NULL) + return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); + } + + /* 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, device->rt_null_ahs); + + return VK_SUCCESS; +} + +void +anv_device_finish_rt_shaders(struct anv_device *device) +{ + if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline) + return; +}