radv: rework and add a helper for hashing a compute pipeline

It should be similar to the previous hashing method but it allows us
to get a hash directly from a pCreateInfo for future work.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28651>
This commit is contained in:
Samuel Pitoiset 2024-04-09 14:51:56 +02:00 committed by Marge Bot
parent 05cd85afc6
commit 9840607f4b
3 changed files with 43 additions and 11 deletions

View file

@ -1204,3 +1204,15 @@ radv_pipeline_hash(const struct radv_device *device, const struct radv_pipeline_
if (pipeline_layout)
_mesa_sha1_update(ctx, pipeline_layout->sha1, sizeof(pipeline_layout->sha1));
}
void
radv_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *sinfo,
const struct radv_shader_stage_key *stage_key, struct mesa_sha1 *ctx)
{
unsigned char shader_sha1[SHA1_DIGEST_LENGTH];
vk_pipeline_hash_shader_stage(sinfo, NULL, shader_sha1);
_mesa_sha1_update(ctx, shader_sha1, sizeof(shader_sha1));
_mesa_sha1_update(ctx, stage_key, sizeof(*stage_key));
}

View file

@ -107,4 +107,7 @@ VkPipelineShaderStageCreateInfo *radv_copy_shader_stage_create_info(struct radv_
void radv_pipeline_hash(const struct radv_device *device, const struct radv_pipeline_layout *pipeline_layout,
struct mesa_sha1 *ctx);
void radv_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *sinfo,
const struct radv_shader_stage_key *stage_key, struct mesa_sha1 *ctx);
#endif /* RADV_PIPELINE_H */

View file

@ -195,11 +195,28 @@ radv_compile_cs(struct radv_device *device, struct vk_pipeline_cache *cache, str
return cs_shader;
}
static void
radv_compute_pipeline_hash(const struct radv_device *device, const VkComputePipelineCreateInfo *pCreateInfo,
unsigned char *hash)
{
VkPipelineCreateFlags2KHR create_flags = vk_compute_pipeline_create_flags(pCreateInfo);
VK_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, pCreateInfo->layout);
const VkPipelineShaderStageCreateInfo *sinfo = &pCreateInfo->stage;
struct mesa_sha1 ctx;
struct radv_shader_stage_key stage_key =
radv_pipeline_get_shader_key(device, sinfo, create_flags, pCreateInfo->pNext);
_mesa_sha1_init(&ctx);
radv_pipeline_hash(device, pipeline_layout, &ctx);
radv_pipeline_hash_shader_stage(sinfo, &stage_key, &ctx);
_mesa_sha1_final(&ctx, hash);
}
static VkResult
radv_compute_pipeline_compile(struct radv_compute_pipeline *pipeline, struct radv_pipeline_layout *pipeline_layout,
struct radv_device *device, struct vk_pipeline_cache *cache,
const struct radv_shader_stage_key *stage_key,
const VkPipelineShaderStageCreateInfo *pStage,
radv_compute_pipeline_compile(const VkComputePipelineCreateInfo *pCreateInfo, struct radv_compute_pipeline *pipeline,
struct radv_pipeline_layout *pipeline_layout, struct radv_device *device,
struct vk_pipeline_cache *cache, const VkPipelineShaderStageCreateInfo *pStage,
const VkPipelineCreationFeedbackCreateInfo *creation_feedback)
{
struct radv_shader_binary *cs_binary = NULL;
@ -215,9 +232,7 @@ radv_compute_pipeline_compile(struct radv_compute_pipeline *pipeline, struct rad
int64_t pipeline_start = os_time_get_nano();
radv_pipeline_stage_init(pStage, pipeline_layout, stage_key, &cs_stage);
radv_hash_shaders(device, hash, &cs_stage, 1, pipeline_layout, NULL);
radv_compute_pipeline_hash(device, pCreateInfo, hash);
pipeline->base.pipeline_hash = *(uint64_t *)hash;
@ -242,6 +257,11 @@ radv_compute_pipeline_compile(struct radv_compute_pipeline *pipeline, struct rad
int64_t stage_start = os_time_get_nano();
const struct radv_shader_stage_key stage_key =
radv_pipeline_get_shader_key(device, &pCreateInfo->stage, pipeline->base.create_flags, pCreateInfo->pNext);
radv_pipeline_stage_init(pStage, pipeline_layout, &stage_key, &cs_stage);
pipeline->base.shaders[MESA_SHADER_COMPUTE] = radv_compile_cs(
device, cache, &cs_stage, keep_executable_info, keep_statistic_info, pipeline->base.is_internal, &cs_binary);
@ -295,10 +315,7 @@ radv_compute_pipeline_create(VkDevice _device, VkPipelineCache _cache, const VkC
const VkPipelineCreationFeedbackCreateInfo *creation_feedback =
vk_find_struct_const(pCreateInfo->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO);
struct radv_shader_stage_key stage_key =
radv_pipeline_get_shader_key(device, &pCreateInfo->stage, pipeline->base.create_flags, pCreateInfo->pNext);
result = radv_compute_pipeline_compile(pipeline, pipeline_layout, device, cache, &stage_key, &pCreateInfo->stage,
result = radv_compute_pipeline_compile(pCreateInfo, pipeline, pipeline_layout, device, cache, &pCreateInfo->stage,
creation_feedback);
if (result != VK_SUCCESS) {
radv_pipeline_destroy(device, &pipeline->base, pAllocator);