2021-02-24 10:58:31 +00:00
|
|
|
/*
|
|
|
|
vulkan_compose.c
|
|
|
|
|
|
|
|
Vulkan compose pass pipeline
|
|
|
|
|
|
|
|
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2021/2/23
|
|
|
|
|
|
|
|
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_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "qfalloca.h"
|
|
|
|
|
2021-12-02 13:48:50 +00:00
|
|
|
#include "QF/cvar.h"
|
2021-02-24 10:58:31 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "QF/Vulkan/qf_compose.h"
|
|
|
|
#include "QF/Vulkan/debug.h"
|
|
|
|
#include "QF/Vulkan/descriptor.h"
|
|
|
|
#include "QF/Vulkan/device.h"
|
|
|
|
#include "QF/Vulkan/image.h"
|
2021-12-02 13:48:50 +00:00
|
|
|
#include "QF/Vulkan/instance.h"
|
2021-12-02 12:58:29 +00:00
|
|
|
#include "QF/Vulkan/renderpass.h"
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
#include "r_internal.h"
|
|
|
|
#include "vid_vulkan.h"
|
|
|
|
|
|
|
|
void
|
2021-12-02 12:58:29 +00:00
|
|
|
Vulkan_Compose_Draw (qfv_renderframe_t *rFrame)
|
2021-02-24 10:58:31 +00:00
|
|
|
{
|
2021-12-02 12:58:29 +00:00
|
|
|
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
|
2021-02-24 10:58:31 +00:00
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
2021-12-02 12:58:29 +00:00
|
|
|
qfv_renderpass_t *renderpass = rFrame->renderpass;
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
composectx_t *cctx = ctx->compose_context;
|
|
|
|
__auto_type frame = &ctx->frames.a[ctx->curFrame];
|
|
|
|
composeframe_t *cframe = &cctx->frames.a[ctx->curFrame];
|
|
|
|
VkCommandBuffer cmd = cframe->cmd;
|
|
|
|
|
2021-12-02 12:58:29 +00:00
|
|
|
DARRAY_APPEND (&rFrame->subpassCmdSets[QFV_passCompose], cmd);
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
dfunc->vkResetCommandBuffer (cmd, 0);
|
|
|
|
VkCommandBufferInheritanceInfo inherit = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
|
2021-12-02 12:58:29 +00:00
|
|
|
renderpass->renderpass, QFV_passCompose,
|
2021-02-24 10:58:31 +00:00
|
|
|
frame->framebuffer,
|
|
|
|
0, 0, 0,
|
|
|
|
};
|
|
|
|
VkCommandBufferBeginInfo beginInfo = {
|
|
|
|
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 0,
|
|
|
|
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
|
|
|
|
| VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, &inherit,
|
|
|
|
};
|
|
|
|
dfunc->vkBeginCommandBuffer (cmd, &beginInfo);
|
|
|
|
|
2021-04-18 11:40:43 +00:00
|
|
|
QFV_duCmdBeginLabel (device, cmd, "compose", { 0, 0.2, 0.6, 1});
|
|
|
|
|
2021-02-24 10:58:31 +00:00
|
|
|
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
cctx->pipeline);
|
|
|
|
|
2021-02-25 04:46:33 +00:00
|
|
|
cframe->imageInfo[0].imageView
|
2021-12-02 12:58:29 +00:00
|
|
|
= renderpass->attachment_views->a[QFV_attachOpaque];
|
2021-02-25 04:46:33 +00:00
|
|
|
cframe->imageInfo[1].imageView
|
2021-12-02 12:58:29 +00:00
|
|
|
= renderpass->attachment_views->a[QFV_attachTranslucent];
|
2021-04-18 11:41:08 +00:00
|
|
|
dfunc->vkUpdateDescriptorSets (device->dev, COMPOSE_IMAGE_INFOS,
|
|
|
|
cframe->descriptors, 0, 0);
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
VkDescriptorSet sets[] = {
|
|
|
|
cframe->descriptors[0].dstSet,
|
|
|
|
};
|
|
|
|
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
cctx->layout, 0, 1, sets, 0, 0);
|
|
|
|
|
2021-03-31 14:38:49 +00:00
|
|
|
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
|
|
|
|
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
|
2021-02-24 10:58:31 +00:00
|
|
|
|
|
|
|
VkDeviceSize offset = 0;
|
|
|
|
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &ctx->quad_buffer, &offset);
|
|
|
|
dfunc->vkCmdDraw (cmd, 4, 1, 0, 0);
|
|
|
|
|
2021-04-18 11:40:43 +00:00
|
|
|
QFV_duCmdEndLabel (device, cmd);
|
2021-02-24 10:58:31 +00:00
|
|
|
dfunc->vkEndCommandBuffer (cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VkDescriptorImageInfo base_image_info = {
|
|
|
|
0, 0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
|
|
|
};
|
|
|
|
static VkWriteDescriptorSet base_image_write = {
|
|
|
|
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0, 0,
|
|
|
|
0, 0, 1,
|
|
|
|
VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
|
|
|
|
0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_Compose_Init (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
|
2021-12-02 13:48:50 +00:00
|
|
|
qfvPushDebug (ctx, "compose init");
|
|
|
|
|
2021-02-24 10:58:31 +00:00
|
|
|
composectx_t *cctx = calloc (1, sizeof (composectx_t));
|
|
|
|
ctx->compose_context = cctx;
|
|
|
|
|
|
|
|
size_t frames = ctx->frames.size;
|
|
|
|
DARRAY_INIT (&cctx->frames, frames);
|
|
|
|
DARRAY_RESIZE (&cctx->frames, frames);
|
|
|
|
cctx->frames.grow = 0;
|
|
|
|
|
|
|
|
cctx->pipeline = Vulkan_CreatePipeline (ctx, "compose");
|
|
|
|
cctx->layout = Vulkan_CreatePipelineLayout (ctx, "compose_layout");
|
|
|
|
|
|
|
|
__auto_type cmdSet = QFV_AllocCommandBufferSet (1, alloca);
|
|
|
|
|
|
|
|
__auto_type attach = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
|
|
|
|
for (size_t i = 0; i < frames; i++) {
|
|
|
|
attach->a[i] = Vulkan_CreateDescriptorSetLayout (ctx,
|
|
|
|
"compose_attach");
|
|
|
|
}
|
|
|
|
__auto_type attach_pool = Vulkan_CreateDescriptorPool (ctx,
|
|
|
|
"compose_attach_pool");
|
|
|
|
|
|
|
|
__auto_type attach_set = QFV_AllocateDescriptorSet (device, attach_pool,
|
|
|
|
attach);
|
|
|
|
for (size_t i = 0; i < frames; i++) {
|
|
|
|
__auto_type cframe = &cctx->frames.a[i];
|
|
|
|
|
|
|
|
QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdSet);
|
|
|
|
cframe->cmd = cmdSet->a[0];
|
|
|
|
|
|
|
|
QFV_duSetObjectName (device, VK_OBJECT_TYPE_COMMAND_BUFFER,
|
|
|
|
cframe->cmd, "cmd:compose");
|
|
|
|
for (int j = 0; j < COMPOSE_IMAGE_INFOS; j++) {
|
|
|
|
cframe->imageInfo[j] = base_image_info;
|
|
|
|
cframe->imageInfo[j].sampler = 0;
|
|
|
|
cframe->descriptors[j] = base_image_write;
|
|
|
|
cframe->descriptors[j].dstSet = attach_set->a[i];
|
|
|
|
cframe->descriptors[j].dstBinding = j;
|
|
|
|
cframe->descriptors[j].pImageInfo = &cframe->imageInfo[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (attach_set);
|
2021-12-02 13:48:50 +00:00
|
|
|
qfvPopDebug (ctx);
|
2021-02-24 10:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Vulkan_Compose_Shutdown (vulkan_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
qfv_device_t *device = ctx->device;
|
|
|
|
qfv_devfuncs_t *dfunc = device->funcs;
|
|
|
|
composectx_t *cctx = ctx->compose_context;
|
|
|
|
|
|
|
|
dfunc->vkDestroyPipeline (device->dev, cctx->pipeline, 0);
|
|
|
|
free (cctx->frames.a);
|
|
|
|
free (cctx);
|
|
|
|
}
|