anv: compute a sampler hash based on parameters

To be used for embedded samplers.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22151>
This commit is contained in:
Lionel Landwerlin 2023-06-08 10:13:37 +03:00 committed by Marge Bot
parent 9506d3f338
commit 6d59168dc9
2 changed files with 16 additions and 2 deletions

View file

@ -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;

View file

@ -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;