mesa/src/vulkan/runtime/vk_descriptor_set_layout.c
Jason Ekstrand 949ce92f05 vulkan: Add a base struct for descriptor set layouts
There's some tricky stuff in here with properly handling Vulkan
allocation scopes and reference counting.  Probably best to do it once.
Also, this means that common code can now take references to descriptor
set layouts which seems useful.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17286>
2022-06-29 20:31:57 +00:00

84 lines
2.9 KiB
C

/*
* Copyright © 2022 Collabora Ltd
*
* 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 "vk_descriptor_set_layout.h"
#include "vk_alloc.h"
#include "vk_common_entrypoints.h"
#include "vk_device.h"
static void
vk_descriptor_set_layout_init(struct vk_device *device,
struct vk_descriptor_set_layout *layout)
{
vk_object_base_init(device, &layout->base,
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
layout->ref_cnt = 1;
}
void *
vk_descriptor_set_layout_zalloc(struct vk_device *device, size_t size)
{
/* Because we're reference counting and lifetimes may not be what the
* client expects, these have to be allocated off the device and not as
* their own object.
*/
struct vk_descriptor_set_layout *layout =
vk_zalloc(&device->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
vk_descriptor_set_layout_init(device, layout);
return layout;
}
void *
vk_descriptor_set_layout_multizalloc(struct vk_device *device,
struct vk_multialloc *ma)
{
/* Because we're reference counting and lifetimes may not be what the
* client expects, these have to be allocated off the device and not as
* their own object.
*/
struct vk_descriptor_set_layout *layout =
vk_multialloc_zalloc(ma, &device->alloc,
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
vk_descriptor_set_layout_init(device, layout);
return layout;
}
VKAPI_ATTR void VKAPI_CALL
vk_common_DestroyDescriptorSetLayout(VkDevice _device,
VkDescriptorSetLayout descriptorSetLayout,
UNUSED const VkAllocationCallbacks *pAllocator)
{
VK_FROM_HANDLE(vk_device, device, _device);
VK_FROM_HANDLE(vk_descriptor_set_layout, layout, descriptorSetLayout);
if (layout == NULL)
return;
vk_descriptor_set_layout_unref(device, layout);
}