mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 11:28:05 +02:00
vk: consolidate dynamic descriptor binding sorting
this code was duplicated across several drivers Reviewed-by: Adam Jackson <ajax@redhat.com> turnip changes Reviewed-by: Hyunjun Ko <zzoon@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9480>
This commit is contained in:
parent
b992b38de6
commit
ad241b15a9
7 changed files with 115 additions and 120 deletions
|
|
@ -29,6 +29,7 @@
|
||||||
#include "util/mesa-sha1.h"
|
#include "util/mesa-sha1.h"
|
||||||
#include "radv_private.h"
|
#include "radv_private.h"
|
||||||
#include "sid.h"
|
#include "sid.h"
|
||||||
|
#include "vk_descriptors.h"
|
||||||
#include "vk_format.h"
|
#include "vk_format.h"
|
||||||
#include "vk_util.h"
|
#include "vk_util.h"
|
||||||
|
|
||||||
|
|
@ -46,28 +47,6 @@ static bool has_equal_immutable_samplers(const VkSampler *samplers, uint32_t cou
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int binding_compare(const void* av, const void *bv)
|
|
||||||
{
|
|
||||||
const VkDescriptorSetLayoutBinding *a = (const VkDescriptorSetLayoutBinding*)av;
|
|
||||||
const VkDescriptorSetLayoutBinding *b = (const VkDescriptorSetLayoutBinding*)bv;
|
|
||||||
|
|
||||||
return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VkDescriptorSetLayoutBinding *
|
|
||||||
create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sorted_bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool radv_mutable_descriptor_type_size_alignment(const VkMutableDescriptorTypeListVALVE *list,
|
static bool radv_mutable_descriptor_type_size_alignment(const VkMutableDescriptorTypeListVALVE *list,
|
||||||
uint64_t *out_size, uint64_t *out_align)
|
uint64_t *out_size, uint64_t *out_align)
|
||||||
{
|
{
|
||||||
|
|
@ -176,8 +155,8 @@ VkResult radv_CreateDescriptorSetLayout(
|
||||||
} else
|
} else
|
||||||
set_layout->ycbcr_sampler_offsets_offset = 0;
|
set_layout->ycbcr_sampler_offsets_offset = 0;
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
|
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||||
pCreateInfo->bindingCount);
|
pCreateInfo->bindingCount);
|
||||||
if (!bindings) {
|
if (!bindings) {
|
||||||
vk_object_base_finish(&set_layout->base);
|
vk_object_base_finish(&set_layout->base);
|
||||||
vk_free2(&device->vk.alloc, pAllocator, set_layout);
|
vk_free2(&device->vk.alloc, pAllocator, set_layout);
|
||||||
|
|
@ -358,8 +337,8 @@ void radv_GetDescriptorSetLayoutSupport(VkDevice device,
|
||||||
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
||||||
VkDescriptorSetLayoutSupport* pSupport)
|
VkDescriptorSetLayoutSupport* pSupport)
|
||||||
{
|
{
|
||||||
VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
|
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||||
pCreateInfo->bindingCount);
|
pCreateInfo->bindingCount);
|
||||||
if (!bindings) {
|
if (!bindings) {
|
||||||
pSupport->supported = false;
|
pSupport->supported = false;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "vk_descriptors.h"
|
||||||
#include "vk_util.h"
|
#include "vk_util.h"
|
||||||
|
|
||||||
#include "v3dv_private.h"
|
#include "v3dv_private.h"
|
||||||
|
|
@ -557,40 +558,6 @@ v3dv_ResetDescriptorPool(VkDevice _device,
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
binding_compare(const void *av, const void *bv)
|
|
||||||
{
|
|
||||||
const VkDescriptorSetLayoutBinding *a =
|
|
||||||
(const VkDescriptorSetLayoutBinding *) av;
|
|
||||||
const VkDescriptorSetLayoutBinding *b =
|
|
||||||
(const VkDescriptorSetLayoutBinding *) bv;
|
|
||||||
|
|
||||||
return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VkDescriptorSetLayoutBinding *
|
|
||||||
create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings,
|
|
||||||
unsigned count,
|
|
||||||
struct v3dv_device *device,
|
|
||||||
const VkAllocationCallbacks *pAllocator)
|
|
||||||
{
|
|
||||||
VkDescriptorSetLayoutBinding *sorted_bindings =
|
|
||||||
vk_alloc2(&device->vk.alloc, pAllocator,
|
|
||||||
count * sizeof(VkDescriptorSetLayoutBinding),
|
|
||||||
8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
|
||||||
|
|
||||||
if (!sorted_bindings)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
memcpy(sorted_bindings, bindings,
|
|
||||||
count * sizeof(VkDescriptorSetLayoutBinding));
|
|
||||||
|
|
||||||
qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding),
|
|
||||||
binding_compare);
|
|
||||||
|
|
||||||
return sorted_bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
v3dv_CreateDescriptorSetLayout(VkDevice _device,
|
v3dv_CreateDescriptorSetLayout(VkDevice _device,
|
||||||
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
||||||
|
|
@ -643,9 +610,8 @@ v3dv_CreateDescriptorSetLayout(VkDevice _device,
|
||||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||||
if (pCreateInfo->bindingCount > 0) {
|
if (pCreateInfo->bindingCount > 0) {
|
||||||
assert(max_binding >= 0);
|
assert(max_binding >= 0);
|
||||||
bindings = create_sorted_bindings(pCreateInfo->pBindings,
|
bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||||
pCreateInfo->bindingCount,
|
pCreateInfo->bindingCount);
|
||||||
device, pAllocator);
|
|
||||||
if (!bindings) {
|
if (!bindings) {
|
||||||
vk_object_free(&device->vk, pAllocator, set_layout);
|
vk_object_free(&device->vk, pAllocator, set_layout);
|
||||||
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
|
@ -719,8 +685,7 @@ v3dv_CreateDescriptorSetLayout(VkDevice _device,
|
||||||
binding->descriptorCount;
|
binding->descriptorCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindings)
|
free(bindings);
|
||||||
vk_free2(&device->vk.alloc, pAllocator, bindings);
|
|
||||||
|
|
||||||
set_layout->descriptor_count = descriptor_count;
|
set_layout->descriptor_count = descriptor_count;
|
||||||
set_layout->dynamic_offset_count = dynamic_offset_count;
|
set_layout->dynamic_offset_count = dynamic_offset_count;
|
||||||
|
|
|
||||||
|
|
@ -44,37 +44,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "util/mesa-sha1.h"
|
#include "util/mesa-sha1.h"
|
||||||
|
#include "vk_descriptors.h"
|
||||||
#include "vk_util.h"
|
#include "vk_util.h"
|
||||||
|
|
||||||
static int
|
|
||||||
binding_compare(const void *av, const void *bv)
|
|
||||||
{
|
|
||||||
const VkDescriptorSetLayoutBinding *a =
|
|
||||||
(const VkDescriptorSetLayoutBinding *) av;
|
|
||||||
const VkDescriptorSetLayoutBinding *b =
|
|
||||||
(const VkDescriptorSetLayoutBinding *) bv;
|
|
||||||
|
|
||||||
return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VkDescriptorSetLayoutBinding *
|
|
||||||
create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings,
|
|
||||||
unsigned count)
|
|
||||||
{
|
|
||||||
VkDescriptorSetLayoutBinding *sorted_bindings =
|
|
||||||
malloc(count * sizeof(VkDescriptorSetLayoutBinding));
|
|
||||||
if (!sorted_bindings)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
memcpy(sorted_bindings, bindings,
|
|
||||||
count * sizeof(VkDescriptorSetLayoutBinding));
|
|
||||||
|
|
||||||
qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding),
|
|
||||||
binding_compare);
|
|
||||||
|
|
||||||
return sorted_bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
descriptor_size(VkDescriptorType type)
|
descriptor_size(VkDescriptorType type)
|
||||||
{
|
{
|
||||||
|
|
@ -160,7 +132,7 @@ tu_CreateDescriptorSetLayout(
|
||||||
struct tu_sampler_ycbcr_conversion *ycbcr_samplers =
|
struct tu_sampler_ycbcr_conversion *ycbcr_samplers =
|
||||||
(void*) &samplers[immutable_sampler_count];
|
(void*) &samplers[immutable_sampler_count];
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(
|
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(
|
||||||
pCreateInfo->pBindings, pCreateInfo->bindingCount);
|
pCreateInfo->pBindings, pCreateInfo->bindingCount);
|
||||||
if (!bindings) {
|
if (!bindings) {
|
||||||
vk_object_free(&device->vk, pAllocator, set_layout);
|
vk_object_free(&device->vk, pAllocator, set_layout);
|
||||||
|
|
@ -275,7 +247,7 @@ tu_GetDescriptorSetLayoutSupport(
|
||||||
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
||||||
VkDescriptorSetLayoutSupport *pSupport)
|
VkDescriptorSetLayoutSupport *pSupport)
|
||||||
{
|
{
|
||||||
VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(
|
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(
|
||||||
pCreateInfo->pBindings, pCreateInfo->bindingCount);
|
pCreateInfo->pBindings, pCreateInfo->bindingCount);
|
||||||
if (!bindings) {
|
if (!bindings) {
|
||||||
pSupport->supported = false;
|
pSupport->supported = false;
|
||||||
|
|
|
||||||
|
|
@ -22,31 +22,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lvp_private.h"
|
#include "lvp_private.h"
|
||||||
|
#include "vk_descriptors.h"
|
||||||
#include "vk_util.h"
|
#include "vk_util.h"
|
||||||
#include "u_math.h"
|
#include "u_math.h"
|
||||||
|
|
||||||
static int binding_compare(const void* av, const void *bv)
|
|
||||||
{
|
|
||||||
const VkDescriptorSetLayoutBinding *a = (const VkDescriptorSetLayoutBinding*)av;
|
|
||||||
const VkDescriptorSetLayoutBinding *b = (const VkDescriptorSetLayoutBinding*)bv;
|
|
||||||
|
|
||||||
return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VkDescriptorSetLayoutBinding *
|
|
||||||
create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sorted_bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorSetLayout(
|
VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorSetLayout(
|
||||||
VkDevice _device,
|
VkDevice _device,
|
||||||
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
||||||
|
|
@ -100,8 +79,8 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorSetLayout(
|
||||||
set_layout->shader_stages = 0;
|
set_layout->shader_stages = 0;
|
||||||
set_layout->size = 0;
|
set_layout->size = 0;
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
|
VkDescriptorSetLayoutBinding *bindings = vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||||
pCreateInfo->bindingCount);
|
pCreateInfo->bindingCount);
|
||||||
if (!bindings) {
|
if (!bindings) {
|
||||||
vk_object_base_finish(&set_layout->base);
|
vk_object_base_finish(&set_layout->base);
|
||||||
vk_free2(&device->vk.alloc, pAllocator, set_layout);
|
vk_free2(&device->vk.alloc, pAllocator, set_layout);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ files_vulkan_util = files(
|
||||||
'vk_debug_report.h',
|
'vk_debug_report.h',
|
||||||
'vk_deferred_operation.c',
|
'vk_deferred_operation.c',
|
||||||
'vk_deferred_operation.h',
|
'vk_deferred_operation.h',
|
||||||
|
'vk_descriptors.c',
|
||||||
|
'vk_descriptors.h',
|
||||||
'vk_device.c',
|
'vk_device.c',
|
||||||
'vk_device.h',
|
'vk_device.h',
|
||||||
'vk_format.c',
|
'vk_format.c',
|
||||||
|
|
|
||||||
55
src/vulkan/util/vk_descriptors.c
Normal file
55
src/vulkan/util/vk_descriptors.c
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2016 Red Hat.
|
||||||
|
* Copyright © 2016 Bas Nieuwenhuizen
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "vk_descriptors.h"
|
||||||
|
#include "util/macros.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
binding_compare(const void* av, const void *bv)
|
||||||
|
{
|
||||||
|
const VkDescriptorSetLayoutBinding *a = (const VkDescriptorSetLayoutBinding*)av;
|
||||||
|
const VkDescriptorSetLayoutBinding *b = (const VkDescriptorSetLayoutBinding*)bv;
|
||||||
|
|
||||||
|
return (a->binding < b->binding) ? -1 : (a->binding > b->binding) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkDescriptorSetLayoutBinding *
|
||||||
|
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sorted_bindings;
|
||||||
|
}
|
||||||
43
src/vulkan/util/vk_descriptors.h
Normal file
43
src/vulkan/util/vk_descriptors.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2016 Red Hat.
|
||||||
|
* Copyright © 2016 Bas Nieuwenhuizen
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the next
|
||||||
|
* paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
* Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
* IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VK_DESCRIPTORS_H
|
||||||
|
#define VK_DESCRIPTORS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
VkDescriptorSetLayoutBinding *
|
||||||
|
vk_create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue