nvk: Fix descriptor offset alignment

This fixes two bugs.  First, we were aligning when setting the bindign
offset but not actually applying that alignment to buffer_size so when
we incremented by stride * descriptorCount, it incremented starting with
the unaligned value.  Second, in some cases we return stride = align = 0
and the ALIGN_POT macro will return 0 when something's aligned to 0.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Faith Ekstrand 2023-01-30 20:11:50 -06:00 committed by Marge Bot
parent 443717a17e
commit fff59a5f4f

View file

@ -183,10 +183,14 @@ nvk_CreateDescriptorSetLayout(VkDevice _device,
nvk_descriptor_stride_align_for_type(binding->descriptorType, type_list,
&stride, &align);
assert(stride <= UINT8_MAX);
layout->binding[b].offset = ALIGN_POT(buffer_size, align);
layout->binding[b].stride = stride;
buffer_size += stride * binding->descriptorCount;
if (stride > 0) {
assert(stride <= UINT8_MAX);
assert(util_is_power_of_two_nonzero(align));
buffer_size = ALIGN_POT(buffer_size, align);
layout->binding[b].offset = buffer_size;
layout->binding[b].stride = stride;
buffer_size += stride * binding->descriptorCount;
}
if (binding_has_immutable_samplers(binding)) {
layout->binding[b].immutable_samplers = samplers;