tu: Refactor immutable sampler handling with descriptor update templates

With subsampled images we need access to the immutable samplers, even
though it's already been written when creating the descriptor set.
Previously we only kept a pointer to them in the template in the push
descriptor case where we needed to write them together with the image.
Refactor the descriptor template path to be more like the normal path
and always save the immutable samplers.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39868>
This commit is contained in:
Connor Abbott 2026-02-27 13:30:21 -05:00 committed by Marge Bot
parent ba3e564327
commit a0a6ee3f4c
2 changed files with 15 additions and 10 deletions

View file

@ -1522,8 +1522,7 @@ tu_CreateDescriptorUpdateTemplate(
}
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case VK_DESCRIPTOR_TYPE_SAMPLER:
if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR &&
binding_layout->immutable_samplers_offset) {
if (binding_layout->immutable_samplers_offset) {
immutable_samplers =
tu_immutable_samplers(set_layout, binding_layout) + entry->dstArrayElement;
}
@ -1540,10 +1539,13 @@ tu_CreateDescriptorUpdateTemplate(
.descriptor_count = entry->descriptorCount,
.dst_offset = dst_offset,
.dst_stride = dst_stride,
.has_sampler = !binding_layout->immutable_samplers_offset,
.immutable_samplers = immutable_samplers,
.src_offset = entry->offset,
.src_stride = entry->stride,
.immutable_samplers = immutable_samplers,
.copy_immutable_samplers =
immutable_samplers &&
pCreateInfo->templateType ==
VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR,
};
}
@ -1634,14 +1636,14 @@ tu_update_descriptor_set_with_template(
write_combined_image_sampler_descriptor(ptr,
templ->entry[i].descriptor_type,
(const VkDescriptorImageInfo *) src,
templ->entry[i].has_sampler);
if (samplers)
!samplers);
if (templ->entry[i].copy_immutable_samplers)
write_sampler_push(ptr + FDL6_TEX_CONST_DWORDS, &samplers[j]);
break;
case VK_DESCRIPTOR_TYPE_SAMPLER:
if (templ->entry[i].has_sampler)
if (!templ->entry[i].immutable_samplers)
write_sampler_descriptor(ptr, ((const VkDescriptorImageInfo *)src)->sampler);
else if (samplers)
else if (templ->entry[i].copy_immutable_samplers)
write_sampler_push(ptr, &samplers[j]);
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: {

View file

@ -183,14 +183,14 @@ struct tu_descriptor_update_template_entry
uint32_t buffer_offset;
/* Only valid for combined image samplers and samplers */
uint16_t has_sampler;
const struct tu_sampler *immutable_samplers;
/* In bytes */
size_t src_offset;
size_t src_stride;
/* For push descriptors */
const struct tu_sampler *immutable_samplers;
bool copy_immutable_samplers;
};
struct tu_descriptor_update_template
@ -226,6 +226,9 @@ static inline const struct tu_sampler *
tu_immutable_samplers(const struct tu_descriptor_set_layout *set,
const struct tu_descriptor_set_binding_layout *binding)
{
if (!binding->immutable_samplers_offset)
return NULL;
return (struct tu_sampler *) ((const char *) set +
binding->immutable_samplers_offset);
}