nvk: Expose pipeline alloc/free functions

This will provide some commonality between graphics and compute.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Faith Ekstrand 2023-01-30 20:11:52 -06:00 committed by Marge Bot
parent ae0d8edc1d
commit 61a91914df
3 changed files with 35 additions and 10 deletions

View file

@ -76,13 +76,11 @@ nvk_compute_pipeline_create(struct nvk_device *device,
struct nvk_compute_pipeline *pipeline;
VkResult result;
pipeline = vk_object_zalloc(&device->vk, pAllocator, sizeof(*pipeline),
VK_OBJECT_TYPE_PIPELINE);
pipeline = (void *)nvk_pipeline_zalloc(device, NVK_PIPELINE_COMPUTE,
sizeof(*pipeline), pAllocator);
if (pipeline == NULL)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
pipeline->base.type = NVK_PIPELINE_COMPUTE;
assert(pCreateInfo->stage.stage == VK_SHADER_STAGE_COMPUTE_BIT);
const nir_shader_compiler_options *nir_options =
@ -111,6 +109,6 @@ nvk_compute_pipeline_create(struct nvk_device *device,
return VK_SUCCESS;
fail:
vk_object_free(&device->vk, pAllocator, pipeline);
nvk_pipeline_free(device, &pipeline->base, pAllocator);
return result;
}

View file

@ -6,10 +6,28 @@
#include "vk_pipeline_cache.h"
static void
nvk_pipeline_destroy(struct nvk_device *device,
struct nvk_pipeline *pipeline,
const VkAllocationCallbacks *pAllocator)
struct nvk_pipeline *
nvk_pipeline_zalloc(struct nvk_device *device,
enum nvk_pipeline_type type, size_t size,
const VkAllocationCallbacks *pAllocator)
{
struct nvk_pipeline *pipeline;
assert(size >= sizeof(*pipeline));
pipeline = vk_object_zalloc(&device->vk, pAllocator, size,
VK_OBJECT_TYPE_PIPELINE);
if (pipeline == NULL)
return NULL;
pipeline->type = type;
return pipeline;
}
void
nvk_pipeline_free(struct nvk_device *device,
struct nvk_pipeline *pipeline,
const VkAllocationCallbacks *pAllocator)
{
for (uint32_t s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
if (pipeline->shaders[s].bo)
@ -99,5 +117,5 @@ nvk_DestroyPipeline(VkDevice _device, VkPipeline _pipeline,
if (!pipeline)
return;
nvk_pipeline_destroy(device, pipeline, pAllocator);
nvk_pipeline_free(device, pipeline, pAllocator);
}

View file

@ -24,6 +24,15 @@ struct nvk_pipeline {
VK_DEFINE_NONDISP_HANDLE_CASTS(nvk_pipeline, base, VkPipeline,
VK_OBJECT_TYPE_PIPELINE)
void
nvk_pipeline_free(struct nvk_device *device,
struct nvk_pipeline *pipeline,
const VkAllocationCallbacks *pAllocator);
struct nvk_pipeline *
nvk_pipeline_zalloc(struct nvk_device *device,
enum nvk_pipeline_type type, size_t size,
const VkAllocationCallbacks *pAllocator);
struct nvk_compute_pipeline {
struct nvk_pipeline base;