From a0a6ee3f4ce357a9c62aa96de2eefe2f04e74da4 Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Fri, 27 Feb 2026 13:30:21 -0500 Subject: [PATCH] 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: --- src/freedreno/vulkan/tu_descriptor_set.cc | 18 ++++++++++-------- src/freedreno/vulkan/tu_descriptor_set.h | 7 +++++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/freedreno/vulkan/tu_descriptor_set.cc b/src/freedreno/vulkan/tu_descriptor_set.cc index 84285a13c39..fbc6fcd5309 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.cc +++ b/src/freedreno/vulkan/tu_descriptor_set.cc @@ -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: { diff --git a/src/freedreno/vulkan/tu_descriptor_set.h b/src/freedreno/vulkan/tu_descriptor_set.h index 48af1bcfe40..d553ffa621d 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.h +++ b/src/freedreno/vulkan/tu_descriptor_set.h @@ -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); }