From 6d59168dc9279d5eac6e7c243a2846d0bd33596c Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 8 Jun 2023 10:13:37 +0300 Subject: [PATCH] anv: compute a sampler hash based on parameters To be used for embedded samplers. Signed-off-by: Lionel Landwerlin Reviewed-by: Ivan Briano Part-of: --- src/intel/vulkan/anv_private.h | 5 +++++ src/intel/vulkan/genX_init_state.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 26d51dcb324..3b6bfb3d8c9 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -5635,6 +5635,11 @@ struct gfx8_border_color { struct anv_sampler { struct vk_sampler vk; + /* Hash of the sampler state + border color, useful for embedded samplers + * and included in the descriptor layout hash. + */ + unsigned char sha1[20]; + uint32_t state[3][4]; uint32_t db_state[3][4]; uint32_t n_planes; diff --git a/src/intel/vulkan/genX_init_state.c b/src/intel/vulkan/genX_init_state.c index 47f80e1e74d..c5f9ff9dc37 100644 --- a/src/intel/vulkan/genX_init_state.c +++ b/src/intel/vulkan/genX_init_state.c @@ -1161,6 +1161,9 @@ VkResult genX(CreateSampler)( const bool seamless_cube = !(pCreateInfo->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT); + struct mesa_sha1 ctx; + _mesa_sha1_init(&ctx); + for (unsigned p = 0; p < sampler->n_planes; p++) { const bool plane_has_chroma = ycbcr_info && ycbcr_info->planes[p].has_chroma; @@ -1217,8 +1220,6 @@ VkResult genX(CreateSampler)( pCreateInfo->compareOp : VK_COMPARE_OP_NEVER], .CubeSurfaceControlMode = seamless_cube ? OVERRIDE : PROGRAMMED, - .BorderColorPointer = border_color_offset, - .LODClampMagnificationMode = MIPNONE, .MaximumAnisotropy = vk_to_intel_max_anisotropy(pCreateInfo->maxAnisotropy), @@ -1240,6 +1241,8 @@ VkResult genX(CreateSampler)( sampler->vk.reduction_mode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, }; + _mesa_sha1_update(&ctx, &sampler_state, sizeof(sampler_state)); + /* Put border color after the hashing, we don't want the allocation * order of border colors to influence the hash. We just need th * parameters to be hashed. @@ -1275,6 +1278,12 @@ VkResult genX(CreateSampler)( } } + /* Hash the border color */ + _mesa_sha1_update(&ctx, border_color_ptr, + sizeof(union isl_color_value)); + + _mesa_sha1_final(&ctx, sampler->sha1); + *pSampler = anv_sampler_to_handle(sampler); return VK_SUCCESS;