mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-04 13:30:11 +01:00
anv: move internal RT shaders around
anv_pipeline.c is about to go. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34872>
This commit is contained in:
parent
d39e443ef8
commit
91abb0e0af
2 changed files with 201 additions and 199 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue