quakeforge/libs/video/renderer/vulkan/pipeline.c

173 lines
4.4 KiB
C
Raw Normal View History

2020-02-12 19:21:35 +00:00
/*
pipeline.c
Vulkan pipeline functions
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2020 Bill Currie <bill@taniwha.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_MATH_H
# include <math.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/input.h"
#include "QF/mathlib.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/Vulkan/qf_vid.h"
#include "QF/Vulkan/descriptor.h"
#include "QF/Vulkan/device.h"
#include "QF/Vulkan/image.h"
#include "QF/Vulkan/instance.h"
#include "QF/Vulkan/pipeline.h"
#include "QF/Vulkan/renderpass.h"
#include "compat.h"
#include "d_iface.h"
#include "r_internal.h"
#include "vid_vulkan.h"
#include "util.h"
VkShaderModule
2020-02-12 19:21:35 +00:00
QFV_CreateShaderModule (qfv_device_t *device,
size_t size, const uint32_t *code)
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
VkShaderModuleCreateInfo createInfo = {
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, 0, 0,
size, code,
};
VkShaderModule module;
dfunc->vkCreateShaderModule (dev, &createInfo, 0, &module);
2020-02-12 19:21:35 +00:00
return module;
}
VkPipelineCache
2020-02-12 19:21:35 +00:00
QFV_CreatePipelineCache (qfv_device_t *device, dstring_t *cacheData)
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
VkPipelineCacheCreateInfo createInfo = {
VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, 0, 0,
cacheData->size, cacheData->str,
};
VkPipelineCache cache;
dfunc->vkCreatePipelineCache (dev, &createInfo, 0, &cache);
2020-02-12 19:21:35 +00:00
return cache;
}
dstring_t *
QFV_GetPipelineCacheData (qfv_device_t *device, VkPipelineCache cache)
2020-02-12 19:21:35 +00:00
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
dstring_t *cacheData = dstring_new ();
dfunc->vkGetPipelineCacheData (dev, cache, &cacheData->size, 0);
2020-02-12 19:21:35 +00:00
dstring_adjust (cacheData);
dfunc->vkGetPipelineCacheData (dev, cache,
&cacheData->size, cacheData->str);
2020-02-12 19:21:35 +00:00
return cacheData;
}
void
QFV_MergePipelineCaches (qfv_device_t *device,
VkPipelineCache targetCache,
2020-02-12 19:21:35 +00:00
qfv_pipelinecacheset_t *sourceCaches)
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
dfunc->vkMergePipelineCaches (dev, targetCache,
sourceCaches->size, sourceCaches->a);
2020-02-12 19:21:35 +00:00
}
VkPipelineLayout
2020-02-12 19:21:35 +00:00
QFV_CreatePipelineLayout (qfv_device_t *device,
qfv_descriptorsetlayoutset_t *layouts,
2020-02-12 19:21:35 +00:00
qfv_pushconstantrangeset_t *pushConstants)
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
VkPipelineLayoutCreateInfo createInfo = {
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, 0, 0,
layouts->size, layouts->a,
pushConstants->size, pushConstants->a,
2020-02-12 19:21:35 +00:00
};
VkPipelineLayout layout;
dfunc->vkCreatePipelineLayout (dev, &createInfo, 0, &layout);
2020-02-12 19:21:35 +00:00
return layout;
}
qfv_pipelineset_t *
QFV_CreateGraphicsPipelines (qfv_device_t *device,
VkPipelineCache cache,
2020-02-12 19:21:35 +00:00
qfv_graphicspipelinecreateinfoset_t *gpciSet)
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
__auto_type pipelines = QFV_AllocPipelineSet (gpciSet->size, malloc);
dfunc->vkCreateGraphicsPipelines (dev, cache, gpciSet->size, gpciSet->a, 0,
pipelines->a);
2020-02-12 19:21:35 +00:00
return pipelines;
2020-02-12 19:21:35 +00:00
}
qfv_pipelineset_t *
QFV_CreateComputePipelines (qfv_device_t *device,
VkPipelineCache cache,
2020-02-12 19:21:35 +00:00
qfv_computepipelinecreateinfoset_t *cpciSet)
{
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
__auto_type pipelines = QFV_AllocPipelineSet (cpciSet->size, malloc);
dfunc->vkCreateComputePipelines (dev, cache, cpciSet->size, cpciSet->a, 0,
pipelines->a);
return pipelines;
2020-02-12 19:21:35 +00:00
}