vulkan/runtime: add a multialloc vk_shader allocator

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33792>
This commit is contained in:
Lionel Landwerlin 2024-08-07 01:02:39 +03:00
parent 009ef67c8d
commit dcb5cfbfcc
2 changed files with 35 additions and 3 deletions

View file

@ -36,6 +36,17 @@
#include "nir.h"
static void
vk_shader_init(struct vk_shader *shader,
struct vk_device *device,
const struct vk_shader_ops *ops,
gl_shader_stage stage)
{
vk_object_base_init(device, &shader->base, VK_OBJECT_TYPE_SHADER_EXT);
shader->ops = ops;
shader->stage = stage;
}
void *
vk_shader_zalloc(struct vk_device *device,
const struct vk_shader_ops *ops,
@ -58,9 +69,25 @@ vk_shader_zalloc(struct vk_device *device,
if (shader == NULL)
return NULL;
vk_object_base_init(device, &shader->base, VK_OBJECT_TYPE_SHADER_EXT);
shader->ops = ops;
shader->stage = stage;
vk_shader_init(shader, device, ops, stage);
return shader;
}
void *
vk_shader_multizalloc(struct vk_device *device,
struct vk_multialloc *ma,
const struct vk_shader_ops *ops,
gl_shader_stage stage,
const VkAllocationCallbacks *alloc)
{
struct vk_shader *shader =
vk_multialloc_zalloc2(ma, &device->alloc, alloc,
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
if (!shader)
return NULL;
vk_shader_init(shader, device, ops, stage);
return shader;
}

View file

@ -152,6 +152,11 @@ void *vk_shader_zalloc(struct vk_device *device,
gl_shader_stage stage,
const VkAllocationCallbacks *alloc,
size_t size);
void *vk_shader_multizalloc(struct vk_device *device,
struct vk_multialloc *ma,
const struct vk_shader_ops *ops,
gl_shader_stage stage,
const VkAllocationCallbacks *alloc);
void vk_shader_free(struct vk_device *device,
const VkAllocationCallbacks *alloc,
struct vk_shader *shader);