radv/rt: refactor radv_rt_pipeline_compile()
This patch moves the NIR shader creation into radv_rt_pipeline_compile() and simplifies radv_rt_pipeline_create(). Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22503>
This commit is contained in:

committed by
Marge Bot

parent
b314c2aae2
commit
dfa5fd480c
@@ -286,43 +286,50 @@ radv_rt_pipeline_compile(struct radv_ray_tracing_pipeline *pipeline,
|
|||||||
struct radv_pipeline_layout *pipeline_layout, struct radv_device *device,
|
struct radv_pipeline_layout *pipeline_layout, struct radv_device *device,
|
||||||
struct vk_pipeline_cache *cache,
|
struct vk_pipeline_cache *cache,
|
||||||
const struct radv_pipeline_key *pipeline_key,
|
const struct radv_pipeline_key *pipeline_key,
|
||||||
const VkPipelineShaderStageCreateInfo *pStage,
|
const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
|
||||||
const VkPipelineCreateFlags flags, const uint8_t *custom_hash,
|
const VkPipelineCreationFeedbackCreateInfo *creation_feedback)
|
||||||
VkPipelineCreationFeedback *pipeline_feedback,
|
|
||||||
struct radv_ray_tracing_group *rt_groups, uint32_t num_rt_groups)
|
|
||||||
{
|
{
|
||||||
struct radv_shader_binary *binaries[MESA_VULKAN_SHADER_STAGES] = {NULL};
|
struct radv_shader_binary *binaries[MESA_VULKAN_SHADER_STAGES] = {NULL};
|
||||||
unsigned char hash[20];
|
bool keep_executable_info = radv_pipeline_capture_shaders(device, pCreateInfo->flags);
|
||||||
bool keep_executable_info = radv_pipeline_capture_shaders(device, flags);
|
bool keep_statistic_info = radv_pipeline_capture_shader_stats(device, pCreateInfo->flags);
|
||||||
bool keep_statistic_info = radv_pipeline_capture_shader_stats(device, flags);
|
|
||||||
struct radv_pipeline_stage rt_stage = {0};
|
struct radv_pipeline_stage rt_stage = {0};
|
||||||
VkResult result = VK_SUCCESS;
|
|
||||||
|
|
||||||
radv_pipeline_stage_init(pStage, &rt_stage, vk_to_mesa_shader_stage(pStage->stage));
|
/* First check if we can get things from the cache before we take the expensive step of
|
||||||
|
* generating the nir. */
|
||||||
|
struct vk_shader_module module = {.base.type = VK_OBJECT_TYPE_SHADER_MODULE};
|
||||||
|
VkPipelineShaderStageCreateInfo stage = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
|
.pNext = NULL,
|
||||||
|
.stage = VK_SHADER_STAGE_RAYGEN_BIT_KHR,
|
||||||
|
.module = vk_shader_module_to_handle(&module),
|
||||||
|
.pName = "main",
|
||||||
|
};
|
||||||
|
|
||||||
if (custom_hash) {
|
radv_pipeline_stage_init(&stage, &rt_stage, vk_to_mesa_shader_stage(stage.stage));
|
||||||
memcpy(hash, custom_hash, 20);
|
|
||||||
} else {
|
|
||||||
radv_hash_shaders(hash, &rt_stage, 1, pipeline_layout, pipeline_key,
|
|
||||||
radv_get_hash_flags(device, keep_statistic_info));
|
|
||||||
}
|
|
||||||
|
|
||||||
pipeline->base.base.pipeline_hash = *(uint64_t *)hash;
|
|
||||||
|
|
||||||
bool found_in_application_cache = true;
|
bool found_in_application_cache = true;
|
||||||
if (!keep_executable_info && radv_pipeline_cache_search(device, cache, &pipeline->base.base,
|
if (!keep_executable_info &&
|
||||||
hash, &found_in_application_cache)) {
|
radv_pipeline_cache_search(device, cache, &pipeline->base.base, pipeline->sha1,
|
||||||
if (found_in_application_cache)
|
&found_in_application_cache)) {
|
||||||
pipeline_feedback->flags |=
|
if (found_in_application_cache && creation_feedback)
|
||||||
|
creation_feedback->pPipelineCreationFeedback->flags |=
|
||||||
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT;
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT;
|
||||||
result = VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT)
|
if (pCreateInfo->flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT)
|
||||||
return VK_PIPELINE_COMPILE_REQUIRED;
|
return VK_PIPELINE_COMPILE_REQUIRED;
|
||||||
|
|
||||||
int64_t stage_start = os_time_get_nano();
|
VkResult result = radv_rt_precompile_shaders(device, cache, pCreateInfo, creation_feedback,
|
||||||
|
pipeline_key, pipeline->stages);
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
VkRayTracingPipelineCreateInfoKHR local_create_info =
|
||||||
|
radv_create_merged_rt_create_info(pCreateInfo);
|
||||||
|
|
||||||
|
rt_stage.internal_nir = create_rt_shader(device, &local_create_info, pipeline->stages,
|
||||||
|
pipeline->groups, pipeline_key);
|
||||||
|
|
||||||
/* Compile SPIR-V shader to NIR. */
|
/* Compile SPIR-V shader to NIR. */
|
||||||
rt_stage.nir =
|
rt_stage.nir =
|
||||||
@@ -333,8 +340,6 @@ radv_rt_pipeline_compile(struct radv_ray_tracing_pipeline *pipeline,
|
|||||||
/* Gather info again, information such as outputs_read can be out-of-date. */
|
/* Gather info again, information such as outputs_read can be out-of-date. */
|
||||||
nir_shader_gather_info(rt_stage.nir, nir_shader_get_entrypoint(rt_stage.nir));
|
nir_shader_gather_info(rt_stage.nir, nir_shader_get_entrypoint(rt_stage.nir));
|
||||||
|
|
||||||
rt_stage.feedback.duration += os_time_get_nano() - stage_start;
|
|
||||||
|
|
||||||
/* Run the shader info pass. */
|
/* Run the shader info pass. */
|
||||||
radv_nir_shader_info_init(&rt_stage.info);
|
radv_nir_shader_info_init(&rt_stage.info);
|
||||||
radv_nir_shader_info_pass(device, rt_stage.nir, MESA_SHADER_NONE, pipeline_layout, pipeline_key,
|
radv_nir_shader_info_pass(device, rt_stage.nir, MESA_SHADER_NONE, pipeline_layout, pipeline_key,
|
||||||
@@ -346,8 +351,6 @@ radv_rt_pipeline_compile(struct radv_ray_tracing_pipeline *pipeline,
|
|||||||
rt_stage.info.user_sgprs_locs = rt_stage.args.user_sgprs_locs;
|
rt_stage.info.user_sgprs_locs = rt_stage.args.user_sgprs_locs;
|
||||||
rt_stage.info.inline_push_constant_mask = rt_stage.args.ac.inline_push_const_mask;
|
rt_stage.info.inline_push_constant_mask = rt_stage.args.ac.inline_push_const_mask;
|
||||||
|
|
||||||
stage_start = os_time_get_nano();
|
|
||||||
|
|
||||||
/* Postprocess NIR. */
|
/* Postprocess NIR. */
|
||||||
radv_postprocess_nir(device, pipeline_layout, pipeline_key, MESA_SHADER_NONE, &rt_stage);
|
radv_postprocess_nir(device, pipeline_layout, pipeline_key, MESA_SHADER_NONE, &rt_stage);
|
||||||
|
|
||||||
@@ -359,20 +362,8 @@ radv_rt_pipeline_compile(struct radv_ray_tracing_pipeline *pipeline,
|
|||||||
radv_shader_nir_to_asm(device, cache, &rt_stage, &rt_stage.nir, 1, pipeline_key,
|
radv_shader_nir_to_asm(device, cache, &rt_stage, &rt_stage.nir, 1, pipeline_key,
|
||||||
keep_executable_info, keep_statistic_info, &binaries[rt_stage.stage]);
|
keep_executable_info, keep_statistic_info, &binaries[rt_stage.stage]);
|
||||||
|
|
||||||
rt_stage.feedback.duration += os_time_get_nano() - stage_start;
|
|
||||||
|
|
||||||
if (keep_executable_info) {
|
|
||||||
struct radv_shader *shader = pipeline->base.base.shaders[rt_stage.stage];
|
|
||||||
|
|
||||||
if (rt_stage.spirv.size) {
|
|
||||||
shader->spirv = malloc(rt_stage.spirv.size);
|
|
||||||
memcpy(shader->spirv, rt_stage.spirv.data, rt_stage.spirv.size);
|
|
||||||
shader->spirv_size = rt_stage.spirv.size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!keep_executable_info) {
|
if (!keep_executable_info) {
|
||||||
radv_pipeline_cache_insert(device, cache, &pipeline->base.base, NULL, hash);
|
radv_pipeline_cache_insert(device, cache, &pipeline->base.base, NULL, pipeline->sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(binaries[rt_stage.stage]);
|
free(binaries[rt_stage.stage]);
|
||||||
@@ -380,10 +371,11 @@ radv_rt_pipeline_compile(struct radv_ray_tracing_pipeline *pipeline,
|
|||||||
radv_dump_shader_stats(device, &pipeline->base.base,
|
radv_dump_shader_stats(device, &pipeline->base.base,
|
||||||
pipeline->base.base.shaders[rt_stage.stage], rt_stage.stage, stderr);
|
pipeline->base.base.shaders[rt_stage.stage], rt_stage.stage, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ralloc_free(rt_stage.internal_nir);
|
||||||
ralloc_free(rt_stage.nir);
|
ralloc_free(rt_stage.nir);
|
||||||
|
|
||||||
done:
|
return VK_SUCCESS;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -500,30 +492,17 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
|||||||
RADV_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, pCreateInfo->layout);
|
RADV_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, pCreateInfo->layout);
|
||||||
VkResult result;
|
VkResult result;
|
||||||
struct radv_ray_tracing_pipeline *pipeline;
|
struct radv_ray_tracing_pipeline *pipeline;
|
||||||
nir_shader *shader = NULL;
|
|
||||||
bool keep_statistic_info = radv_pipeline_capture_shader_stats(device, pCreateInfo->flags);
|
bool keep_statistic_info = radv_pipeline_capture_shader_stats(device, pCreateInfo->flags);
|
||||||
const VkPipelineCreationFeedbackCreateInfo *creation_feedback =
|
const VkPipelineCreationFeedbackCreateInfo *creation_feedback =
|
||||||
vk_find_struct_const(pCreateInfo->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO);
|
vk_find_struct_const(pCreateInfo->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO);
|
||||||
VkPipelineCreationFeedback pipeline_feedback = {
|
if (creation_feedback)
|
||||||
.flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT,
|
creation_feedback->pPipelineCreationFeedback->flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT;
|
||||||
};
|
|
||||||
int64_t pipeline_start = os_time_get_nano();
|
int64_t pipeline_start = os_time_get_nano();
|
||||||
|
|
||||||
VkRayTracingPipelineCreateInfoKHR local_create_info =
|
VkRayTracingPipelineCreateInfoKHR local_create_info =
|
||||||
radv_create_merged_rt_create_info(pCreateInfo);
|
radv_create_merged_rt_create_info(pCreateInfo);
|
||||||
|
|
||||||
struct vk_shader_module module = {.base.type = VK_OBJECT_TYPE_SHADER_MODULE};
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo stage = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
||||||
.pNext = NULL,
|
|
||||||
.stage = VK_SHADER_STAGE_RAYGEN_BIT_KHR,
|
|
||||||
.module = vk_shader_module_to_handle(&module),
|
|
||||||
.pName = "main",
|
|
||||||
};
|
|
||||||
VkPipelineCreateFlags flags =
|
|
||||||
pCreateInfo->flags | VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT;
|
|
||||||
|
|
||||||
size_t pipeline_size =
|
size_t pipeline_size =
|
||||||
sizeof(*pipeline) + local_create_info.groupCount * sizeof(struct radv_ray_tracing_group);
|
sizeof(*pipeline) + local_create_info.groupCount * sizeof(struct radv_ray_tracing_group);
|
||||||
pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, pipeline_size, 8,
|
pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, pipeline_size, 8,
|
||||||
@@ -554,6 +533,7 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
|||||||
|
|
||||||
radv_hash_rt_shaders(pipeline->sha1, pCreateInfo, &key, pipeline->groups,
|
radv_hash_rt_shaders(pipeline->sha1, pCreateInfo, &key, pipeline->groups,
|
||||||
radv_get_hash_flags(device, keep_statistic_info));
|
radv_get_hash_flags(device, keep_statistic_info));
|
||||||
|
pipeline->base.base.pipeline_hash = *(uint64_t *)pipeline->sha1;
|
||||||
|
|
||||||
if (pCreateInfo->flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) {
|
if (pCreateInfo->flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) {
|
||||||
result = radv_rt_precompile_shaders(device, cache, pCreateInfo, creation_feedback, &key,
|
result = radv_rt_precompile_shaders(device, cache, pCreateInfo, creation_feedback, &key,
|
||||||
@@ -561,30 +541,8 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First check if we can get things from the cache before we take the expensive step of
|
result = radv_rt_pipeline_compile(pipeline, pipeline_layout, device, cache, &key, pCreateInfo,
|
||||||
* generating the nir. */
|
creation_feedback);
|
||||||
result = radv_rt_pipeline_compile(pipeline, pipeline_layout, device, cache, &key, &stage, flags,
|
|
||||||
pipeline->sha1, &pipeline_feedback, pipeline->groups,
|
|
||||||
pipeline->group_count);
|
|
||||||
|
|
||||||
if (result == VK_PIPELINE_COMPILE_REQUIRED) {
|
|
||||||
if (pCreateInfo->flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
result =
|
|
||||||
radv_rt_precompile_shaders(device, cache, pCreateInfo, creation_feedback, &key, pipeline->stages);
|
|
||||||
if (result != VK_SUCCESS)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
shader = create_rt_shader(device, &local_create_info, pipeline->stages, pipeline->groups, &key);
|
|
||||||
module.nir = shader;
|
|
||||||
|
|
||||||
result = radv_rt_pipeline_compile(
|
|
||||||
pipeline, pipeline_layout, device, cache, &key, &stage, pCreateInfo->flags,
|
|
||||||
pipeline->sha1, &pipeline_feedback, pipeline->groups, pipeline->group_count);
|
|
||||||
|
|
||||||
ralloc_free(shader);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
goto done;
|
goto done;
|
||||||
@@ -604,10 +562,8 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache,
|
|||||||
radv_rmv_log_compute_pipeline_create(device, pCreateInfo->flags, &pipeline->base.base, false);
|
radv_rmv_log_compute_pipeline_create(device, pCreateInfo->flags, &pipeline->base.base, false);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (creation_feedback) {
|
if (creation_feedback)
|
||||||
pipeline_feedback.duration = os_time_get_nano() - pipeline_start;
|
creation_feedback->pPipelineCreationFeedback->duration = os_time_get_nano() - pipeline_start;
|
||||||
*creation_feedback->pPipelineCreationFeedback = pipeline_feedback;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == VK_SUCCESS)
|
if (result == VK_SUCCESS)
|
||||||
*pPipeline = radv_pipeline_to_handle(&pipeline->base.base);
|
*pPipeline = radv_pipeline_to_handle(&pipeline->base.base);
|
||||||
|
Reference in New Issue
Block a user