tu,radv: fix potentially wrong offset of flexible array.

v2. Remove redundant memset and make the expression simpler.

Signed-off-by: Hyunjun Ko <zzoon@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5703>
This commit is contained in:
Hyunjun Ko 2020-07-01 03:13:40 +00:00 committed by Marge Bot
parent e2209e869a
commit 9190cc9b15
2 changed files with 6 additions and 10 deletions

View File

@ -102,8 +102,8 @@ VkResult radv_CreateDescriptorSetLayout(
}
}
uint32_t samplers_offset = sizeof(struct radv_descriptor_set_layout) +
(max_binding + 1) * sizeof(set_layout->binding[0]);
uint32_t samplers_offset =
offsetof(struct radv_descriptor_set_layout, binding[max_binding + 1]);
size_t size = samplers_offset + immutable_sampler_count * 4 * sizeof(uint32_t);
if (ycbcr_sampler_count > 0) {
size += ycbcr_sampler_count * sizeof(struct radv_sampler_ycbcr_conversion) + (max_binding + 1) * sizeof(uint32_t);
@ -146,8 +146,6 @@ VkResult radv_CreateDescriptorSetLayout(
set_layout->has_immutable_samplers = false;
set_layout->size = 0;
memset(set_layout->binding, 0, size - sizeof(struct radv_descriptor_set_layout));
uint32_t buffer_count = 0;
uint32_t dynamic_offset_count = 0;

View File

@ -139,15 +139,16 @@ tu_CreateDescriptorSetLayout(
}
}
uint32_t samplers_offset = sizeof(struct tu_descriptor_set_layout) +
(max_binding + 1) * sizeof(set_layout->binding[0]);
uint32_t samplers_offset =
offsetof(struct tu_descriptor_set_layout, binding[max_binding + 1]);
/* note: only need to store TEX_SAMP_DWORDS for immutable samples,
* but using struct tu_sampler makes things simpler */
uint32_t size = samplers_offset +
immutable_sampler_count * sizeof(struct tu_sampler) +
ycbcr_sampler_count * sizeof(struct tu_sampler_ycbcr_conversion);
set_layout = vk_alloc2(&device->alloc, pAllocator, size, 8,
set_layout = vk_zalloc2(&device->alloc, pAllocator, size, 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!set_layout)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
@ -172,9 +173,6 @@ tu_CreateDescriptorSetLayout(
set_layout->size = 0;
set_layout->dynamic_ubo = 0;
memset(set_layout->binding, 0,
size - sizeof(struct tu_descriptor_set_layout));
uint32_t dynamic_offset_count = 0;
uint32_t buffer_count = 0;