vulkan: Fix descriptor set creation with zero bindings.
MAX2(count * struct size, 1) results in 1 for count=0, not the size of a struct.
Since this MAX only seems to exist so we can keep using NULL for error reporting,
just refactor to return a VkResult.
Fixes: ad241b15a9
("vk: consolidate dynamic descriptor binding sorting")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4522
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9880>
This commit is contained in:
parent
80b90a0f2b
commit
83c92a48b7
|
@ -155,12 +155,14 @@ VkResult radv_CreateDescriptorSetLayout(
|
|||
} else
|
||||
set_layout->ycbcr_sampler_offsets_offset = 0;
|
||||
|
||||
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount);
|
||||
if (!bindings) {
|
||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||
VkResult result = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount,
|
||||
&bindings);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_object_base_finish(&set_layout->base);
|
||||
vk_free2(&device->vk.alloc, pAllocator, set_layout);
|
||||
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
return vk_error(device->instance, result);
|
||||
}
|
||||
|
||||
set_layout->binding_count = num_bindings;
|
||||
|
@ -337,9 +339,11 @@ void radv_GetDescriptorSetLayoutSupport(VkDevice device,
|
|||
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
||||
VkDescriptorSetLayoutSupport* pSupport)
|
||||
{
|
||||
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount);
|
||||
if (!bindings) {
|
||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||
VkResult result = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount,
|
||||
&bindings);
|
||||
if (result != VK_SUCCESS) {
|
||||
pSupport->supported = false;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -607,15 +607,14 @@ v3dv_CreateDescriptorSetLayout(VkDevice _device,
|
|||
/* We just allocate all the immutable samplers at the end of the struct */
|
||||
struct v3dv_sampler *samplers = (void*) &set_layout->binding[max_binding + 1];
|
||||
|
||||
assert(pCreateInfo->bindingCount == 0 || max_binding >= 0);
|
||||
|
||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||
if (pCreateInfo->bindingCount > 0) {
|
||||
assert(max_binding >= 0);
|
||||
bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount);
|
||||
if (!bindings) {
|
||||
VkResult result = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount, &bindings);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_object_free(&device->vk, pAllocator, set_layout);
|
||||
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
}
|
||||
return vk_error(device->instance, result);
|
||||
}
|
||||
|
||||
memset(set_layout->binding, 0,
|
||||
|
|
|
@ -132,11 +132,12 @@ tu_CreateDescriptorSetLayout(
|
|||
struct tu_sampler_ycbcr_conversion *ycbcr_samplers =
|
||||
(void*) &samplers[immutable_sampler_count];
|
||||
|
||||
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(
|
||||
pCreateInfo->pBindings, pCreateInfo->bindingCount);
|
||||
if (!bindings) {
|
||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||
VkResult result = vk_create_sorted_bindings(
|
||||
pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_object_free(&device->vk, pAllocator, set_layout);
|
||||
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
return vk_error(device->instance, result);
|
||||
}
|
||||
|
||||
set_layout->binding_count = max_binding + 1;
|
||||
|
@ -247,9 +248,10 @@ tu_GetDescriptorSetLayoutSupport(
|
|||
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
||||
VkDescriptorSetLayoutSupport *pSupport)
|
||||
{
|
||||
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(
|
||||
pCreateInfo->pBindings, pCreateInfo->bindingCount);
|
||||
if (!bindings) {
|
||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||
VkResult result = vk_create_sorted_bindings(
|
||||
pCreateInfo->pBindings, pCreateInfo->bindingCount, &bindings);
|
||||
if (result != VK_SUCCESS) {
|
||||
pSupport->supported = false;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -79,12 +79,14 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorSetLayout(
|
|||
set_layout->shader_stages = 0;
|
||||
set_layout->size = 0;
|
||||
|
||||
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount);
|
||||
if (!bindings) {
|
||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||
VkResult result = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||
pCreateInfo->bindingCount,
|
||||
&bindings);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_object_base_finish(&set_layout->base);
|
||||
vk_free2(&device->vk.alloc, pAllocator, set_layout);
|
||||
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
return vk_error(device->instance, result);
|
||||
}
|
||||
|
||||
uint32_t dynamic_offset_count = 0;
|
||||
|
|
|
@ -36,20 +36,21 @@ binding_compare(const void* av, const void *bv)
|
|||
return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
|
||||
}
|
||||
|
||||
VkDescriptorSetLayoutBinding *
|
||||
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count)
|
||||
VkResult
|
||||
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count,
|
||||
VkDescriptorSetLayoutBinding **sorted_bindings)
|
||||
{
|
||||
VkDescriptorSetLayoutBinding *sorted_bindings = malloc(MAX2(count * sizeof(VkDescriptorSetLayoutBinding), 1));
|
||||
if (!sorted_bindings)
|
||||
return NULL;
|
||||
|
||||
if (count) {
|
||||
memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
|
||||
qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
|
||||
} else {
|
||||
/* just an empty struct */
|
||||
memset(sorted_bindings, 0, sizeof(VkDescriptorSetLayoutBinding));
|
||||
if (!count) {
|
||||
*sorted_bindings = NULL;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
return sorted_bindings;
|
||||
*sorted_bindings = malloc(count * sizeof(VkDescriptorSetLayoutBinding));
|
||||
if (!*sorted_bindings)
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
|
||||
memcpy(*sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
|
||||
qsort(*sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,9 @@ extern "C" {
|
|||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
VkDescriptorSetLayoutBinding *
|
||||
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count);
|
||||
VkResult
|
||||
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count,
|
||||
VkDescriptorSetLayoutBinding **sorted_bindings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue