vulkan/runtime: introduce vk_meta_object_list

Code movement: Move the object list + destroy_object
function to separate files.

This allows vk_command_buffer.{h, c} to not depend on all
of vk_meta, which depends on vk_pipeline, which depends on
NIR.

Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30355>
This commit is contained in:
Gurchetan Singh
2024-01-10 15:09:02 -08:00
committed by Marge Bot
parent 97ed2e4d4b
commit 7cc199502f
6 changed files with 113 additions and 84 deletions

View File

@@ -28,6 +28,7 @@ vulkan_lite_runtime_files = files(
'vk_graphics_state.c',
'vk_image.c',
'vk_log.c',
'vk_meta_object_list.c',
'vk_object.c',
'vk_physical_device.c',
'vk_pipeline_layout.c',

View File

@@ -27,7 +27,7 @@
#include "vk_cmd_queue.h"
#include "vk_graphics_state.h"
#include "vk_log.h"
#include "vk_meta.h"
#include "vk_meta_object_list.h"
#include "vk_object.h"
#include "util/list.h"
#include "util/u_dynarray.h"

View File

@@ -21,6 +21,7 @@
* IN THE SOFTWARE.
*/
#include "vk_meta_object_list.h"
#include "vk_meta_private.h"
#include "vk_command_buffer.h"
@@ -74,36 +75,6 @@ cache_key_equal(const void *_a, const void *_b)
return memcmp(a->key_data, b->key_data, a->key_size) == 0;
}
static void
destroy_object(struct vk_device *device, struct vk_object_base *obj)
{
const struct vk_device_dispatch_table *disp = &device->dispatch_table;
VkDevice _device = vk_device_to_handle(device);
switch (obj->type) {
case VK_OBJECT_TYPE_BUFFER:
disp->DestroyBuffer(_device, (VkBuffer)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_IMAGE_VIEW:
disp->DestroyImageView(_device, (VkImageView)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
disp->DestroyDescriptorSetLayout(_device, (VkDescriptorSetLayout)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
disp->DestroyPipelineLayout(_device, (VkPipelineLayout)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_PIPELINE:
disp->DestroyPipeline(_device, (VkPipeline)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_SAMPLER:
disp->DestroySampler(_device, (VkSampler)(uintptr_t)obj, NULL);
break;
default:
unreachable("Unsupported object type");
}
}
VkResult
vk_meta_device_init(struct vk_device *device,
struct vk_meta_device *meta)
@@ -126,7 +97,7 @@ vk_meta_device_finish(struct vk_device *device,
{
hash_table_foreach(meta->cache, entry) {
free((void *)entry->key);
destroy_object(device, entry->data);
vk_meta_destroy_object(device, entry->data);
}
_mesa_hash_table_destroy(meta->cache, NULL);
simple_mtx_destroy(&meta->cache_mtx);
@@ -190,7 +161,7 @@ vk_meta_cache_object(struct vk_device *device,
if (entry != NULL) {
/* We raced and found that object already in the cache */
free(key);
destroy_object(device, obj);
vk_meta_destroy_object(device, obj);
return (uint64_t)(uintptr_t)entry->data;
} else {
/* Return the newly inserted object */
@@ -527,30 +498,6 @@ vk_meta_create_compute_pipeline(struct vk_device *device,
return VK_SUCCESS;
}
void
vk_meta_object_list_init(struct vk_meta_object_list *mol)
{
util_dynarray_init(&mol->arr, NULL);
}
void
vk_meta_object_list_reset(struct vk_device *device,
struct vk_meta_object_list *mol)
{
util_dynarray_foreach(&mol->arr, struct vk_object_base *, obj)
destroy_object(device, *obj);
util_dynarray_clear(&mol->arr);
}
void
vk_meta_object_list_finish(struct vk_device *device,
struct vk_meta_object_list *mol)
{
vk_meta_object_list_reset(device, mol);
util_dynarray_fini(&mol->arr);
}
VkResult
vk_meta_create_buffer(struct vk_command_buffer *cmd,
struct vk_meta_device *meta,

View File

@@ -27,7 +27,6 @@
#include "vk_object.h"
#include "util/simple_mtx.h"
#include "util/u_dynarray.h"
#ifdef __cplusplus
extern "C" {
@@ -181,32 +180,6 @@ vk_meta_create_sampler(struct vk_device *device,
const void *key_data, size_t key_size,
VkSampler *sampler_out);
struct vk_meta_object_list {
struct util_dynarray arr;
};
void vk_meta_object_list_init(struct vk_meta_object_list *mol);
void vk_meta_object_list_reset(struct vk_device *device,
struct vk_meta_object_list *mol);
void vk_meta_object_list_finish(struct vk_device *device,
struct vk_meta_object_list *mol);
static inline void
vk_meta_object_list_add_obj(struct vk_meta_object_list *mol,
struct vk_object_base *obj)
{
util_dynarray_append(&mol->arr, struct vk_object_base *, obj);
}
static inline void
vk_meta_object_list_add_handle(struct vk_meta_object_list *mol,
VkObjectType obj_type,
uint64_t handle)
{
vk_meta_object_list_add_obj(mol,
vk_object_base_from_u64_handle(handle, obj_type));
}
VkResult vk_meta_create_buffer(struct vk_command_buffer *cmd,
struct vk_meta_device *meta,
const VkBufferCreateInfo *info,

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2022 Collabora Ltd
* Copyright 2024 Google LLC
* SPDX-License-Identifier: MIT
*/
#include "vk_meta_object_list.h"
#include "vk_device.h"
void
vk_meta_destroy_object(struct vk_device *device, struct vk_object_base *obj)
{
const struct vk_device_dispatch_table *disp = &device->dispatch_table;
VkDevice _device = vk_device_to_handle(device);
switch (obj->type) {
case VK_OBJECT_TYPE_BUFFER:
disp->DestroyBuffer(_device, (VkBuffer)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_IMAGE_VIEW:
disp->DestroyImageView(_device, (VkImageView)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
disp->DestroyDescriptorSetLayout(_device, (VkDescriptorSetLayout)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
disp->DestroyPipelineLayout(_device, (VkPipelineLayout)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_PIPELINE:
disp->DestroyPipeline(_device, (VkPipeline)(uintptr_t)obj, NULL);
break;
case VK_OBJECT_TYPE_SAMPLER:
disp->DestroySampler(_device, (VkSampler)(uintptr_t)obj, NULL);
break;
default:
unreachable("Unsupported object type");
}
}
void
vk_meta_object_list_init(struct vk_meta_object_list *mol)
{
util_dynarray_init(&mol->arr, NULL);
}
void
vk_meta_object_list_reset(struct vk_device *device,
struct vk_meta_object_list *mol)
{
util_dynarray_foreach(&mol->arr, struct vk_object_base *, obj)
vk_meta_destroy_object(device, *obj);
util_dynarray_clear(&mol->arr);
}
void
vk_meta_object_list_finish(struct vk_device *device,
struct vk_meta_object_list *mol)
{
vk_meta_object_list_reset(device, mol);
util_dynarray_fini(&mol->arr);
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2022 Collabora Ltd
* Copyright 2024 Google LLC
* SPDX-License-Identifier: MIT
*/
#ifndef VK_META_OBJECT_LIST_H
#define VK_META_OBJECT_LIST_H
#include "vk_object.h"
#include "util/u_dynarray.h"
struct vk_device;
struct vk_meta_object_list {
struct util_dynarray arr;
};
void vk_meta_object_list_init(struct vk_meta_object_list *mol);
void vk_meta_object_list_reset(struct vk_device *device,
struct vk_meta_object_list *mol);
void vk_meta_object_list_finish(struct vk_device *device,
struct vk_meta_object_list *mol);
static inline void
vk_meta_object_list_add_obj(struct vk_meta_object_list *mol,
struct vk_object_base *obj)
{
util_dynarray_append(&mol->arr, struct vk_object_base *, obj);
}
static inline void
vk_meta_object_list_add_handle(struct vk_meta_object_list *mol,
VkObjectType obj_type,
uint64_t handle)
{
vk_meta_object_list_add_obj(mol,
vk_object_base_from_u64_handle(handle, obj_type));
}
void vk_meta_destroy_object(struct vk_device *device,
struct vk_object_base *obj);
#endif