mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 12:31:10 +00:00
[vulkan] Begin work on a new render pass system
While the old system did get things going, it felt clunky to set up, especially when it came to variations on render passes (eg, flat vs cube-mapped). Also, much of it felt inside-out, especially the separation of pipelines and render passes: having to specify the render pass and subpass in the pipeline spec made the spec feel overly coupled to the render pass setup. While this is the case in Vulkan, it is not reflected properly in the pipeline spec. The new system will adjust the render pass and subpass parameters of the pipeline spec as needed, making the pipeline specs more reusable, and hopefully less error prone as the pipelines are directly referenced by the subpasses that use them. In addition, subpass dependencies should be much easier to set up as only the dependent subpass specifies the dependency and the subpass source dependency is mentioned by name. Frame buffer attachments also get a similar treatment. The new spec "format" isn't quite finalized (needs to meet the enemy known as parsing) but it feels like a good starting place.
This commit is contained in:
parent
477057a5ad
commit
7c1aff6736
3 changed files with 559 additions and 0 deletions
66
include/QF/Vulkan/render.h
Normal file
66
include/QF/Vulkan/render.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef __QF_Vulkan_render_h
|
||||
#define __QF_Vulkan_render_h
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
#define VK_NO_PROTOTYPES
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include "QF/darray.h"
|
||||
#include "QF/simd/types.h"
|
||||
|
||||
typedef struct qfv_label_s {
|
||||
vec4f_t color;
|
||||
const char *name;
|
||||
} qfv_label_t;
|
||||
|
||||
typedef struct qfv_bar_s {
|
||||
VkBuffer *buffers;
|
||||
VkDeviceSize *offsets;
|
||||
uint32_t firstBinding;
|
||||
uint32_t bindingCount;
|
||||
} qfv_bar_t;
|
||||
|
||||
typedef struct qfv_pipeline_s {
|
||||
qfv_label_t label;
|
||||
VkPipelineBindPoint bindPoint;
|
||||
VkPipeline pipeline;
|
||||
VkPipelineLayout layout;
|
||||
VkViewport viewport;
|
||||
VkRect2D scissor;
|
||||
struct qfv_push_constants_s *push_constants;
|
||||
uint32_t num_push_constants;
|
||||
uint32_t num_descriptor_sets;
|
||||
uint32_t first_descriptor_set;
|
||||
VkDescriptorSet *descriptor_sets;
|
||||
} qfv_pipeline_t;
|
||||
|
||||
typedef struct qfv_subpass_s {
|
||||
qfv_label_t label;
|
||||
VkCommandBufferBeginInfo beginInfo;
|
||||
VkCommandBuffer cmd;
|
||||
uint32_t pipline_count;
|
||||
qfv_pipeline_t *pipelines;
|
||||
} qfv_subpass_t;
|
||||
|
||||
typedef struct qfv_renderpass_s {
|
||||
struct vulkan_ctx_s *vulkan_ctx;
|
||||
qfv_label_t label; // for debugging
|
||||
|
||||
VkCommandBuffer cmd;
|
||||
VkRenderPassBeginInfo beginInfo;
|
||||
VkSubpassContents subpassContents;
|
||||
|
||||
//struct qfv_imageset_s *attachment_images;
|
||||
//struct qfv_imageviewset_s *attachment_views;
|
||||
//VkDeviceMemory attachmentMemory;
|
||||
//size_t attachmentMemory_size;
|
||||
//qfv_output_t output;
|
||||
|
||||
uint32_t subpass_count;
|
||||
qfv_subpass_t *subpasses;
|
||||
} qfv_renderpass_t;
|
||||
|
||||
void QFV_RunRenderPass (qfv_renderpass_t *rp, struct vulkan_ctx_s *ctx)m
|
||||
|
||||
#endif//__QF_Vulkan_render_h
|
122
libs/video/renderer/vulkan/render.c
Normal file
122
libs/video/renderer/vulkan/render.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
render.c
|
||||
|
||||
Vulkan render manager
|
||||
|
||||
Copyright (C) 2023 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/Vulkan/command.h"
|
||||
#include "QF/Vulkan/debug.h"
|
||||
#include "QF/Vulkan/device.h"
|
||||
#include "QF/Vulkan/render.h"
|
||||
#include "QF/Vulkan/pipeline.h"
|
||||
#include "vid_vulkan.h"
|
||||
|
||||
static void
|
||||
run_pipeline (qfv_pipeline_t *pipeline, VkCommandBuffer cmd, vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
dfunc->vkCmdBindPipeline (cmd, pipeline->bindPoint, pipeline->pipeline);
|
||||
dfunc->vkCmdSetViewport (cmd, 0, 1, &pipeline->viewport);
|
||||
dfunc->vkCmdSetScissor (cmd, 0, 1, &pipeline->scissor);
|
||||
if (pipeline->num_descriptor_sets) {
|
||||
dfunc->vkCmdBindDescriptorSets (cmd, pipeline->bindPoint,
|
||||
pipeline->layout,
|
||||
pipeline->first_descriptor_set,
|
||||
pipeline->num_descriptor_sets,
|
||||
pipeline->descriptor_sets,
|
||||
0, 0);
|
||||
}
|
||||
if (pipeline->num_push_constants) {
|
||||
QFV_PushConstants (device, cmd, pipeline->layout,
|
||||
pipeline->num_push_constants,
|
||||
pipeline->push_constants);
|
||||
}
|
||||
}
|
||||
|
||||
// https://themaister.net/blog/2019/08/14/yet-another-blog-explaining-vulkan-synchronization/
|
||||
static void
|
||||
run_subpass (qfv_subpass_t *sp, vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
__auto_type cmd = sp->cmd;
|
||||
dfunc->vkResetCommandBuffer (cmd, 0);
|
||||
dfunc->vkBeginCommandBuffer (cmd, &sp->beginInfo);
|
||||
QFV_duCmdBeginLabel (device, cmd, sp->label.name,
|
||||
{VEC4_EXP (sp->label.color)});
|
||||
|
||||
for (uint32_t i = 0; i < sp->pipline_count; i++) {
|
||||
__auto_type pipeline = &sp->pipelines[i];
|
||||
run_pipeline (pipeline, cmd, ctx);
|
||||
}
|
||||
|
||||
QFV_duCmdEndLabel (device, cmd);
|
||||
dfunc->vkEndCommandBuffer (cmd);
|
||||
}
|
||||
|
||||
void
|
||||
QFV_RunRenderPass (qfv_renderpass_t *rp, vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
__auto_type cmd = rp->cmd;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
};
|
||||
dfunc->vkResetCommandBuffer (cmd, 0);
|
||||
dfunc->vkBeginCommandBuffer (cmd, &beginInfo);
|
||||
QFV_duCmdBeginLabel (device, cmd, rp->label.name,
|
||||
{VEC4_EXP (rp->label.color)});
|
||||
dfunc->vkCmdBeginRenderPass (cmd, &rp->beginInfo, rp->subpassContents);
|
||||
for (uint32_t i = 0; i < rp->subpass_count; i++) {
|
||||
__auto_type sp = &rp->subpasses[i];
|
||||
run_subpass (sp, ctx);
|
||||
dfunc->vkCmdExecuteCommands (cmd, 1, &sp->cmd);
|
||||
//FIXME comment is a bit off as exactly one buffer is always submitted
|
||||
//
|
||||
//Regardless of whether any commands were submitted for this
|
||||
//subpass, must step through each and every subpass, otherwise
|
||||
//the attachments won't be transitioned correctly.
|
||||
//However, only if not the last (or only) subpass.
|
||||
if (i < rp->subpass_count - 1) {
|
||||
dfunc->vkCmdNextSubpass (cmd, rp->subpassContents);
|
||||
}
|
||||
}
|
||||
QFV_CmdEndLabel (device, cmd);
|
||||
}
|
371
libs/video/renderer/vulkan/rp_main_def.plist
Normal file
371
libs/video/renderer/vulkan/rp_main_def.plist
Normal file
|
@ -0,0 +1,371 @@
|
|||
properties {
|
||||
color = {
|
||||
bsp = "[0, 0.5, 0.6, 1]";
|
||||
alias = "[0.6, 0.5, 0, 1]";
|
||||
iqm = "[0.6, 0.5, 0, 1]";
|
||||
sprite = "[0.6, 0.5, 0, 1]";
|
||||
};
|
||||
color_dependency = {
|
||||
src = {
|
||||
stage = color_attachment_output;
|
||||
access = color_attachment_write;
|
||||
};
|
||||
dst = {
|
||||
stage = fragment_shader;
|
||||
access = input_attachment_read;
|
||||
};
|
||||
flags = by_region;
|
||||
};
|
||||
depth_dependency = {
|
||||
src = {
|
||||
stage = late_fragment_tests;
|
||||
access = depth_stencil_attachment_write;
|
||||
};
|
||||
dst = {
|
||||
stage = fragment_shader|early_fragment_tests;
|
||||
access = input_attachment_read|depth_stencil_attachment_read;
|
||||
};
|
||||
flags = by_region;
|
||||
};
|
||||
image_base = {
|
||||
imageType = `2d;
|
||||
samples = 1;
|
||||
extent = {
|
||||
width = $output.extent.width;
|
||||
height = $output.extent.height;
|
||||
depth = 1;
|
||||
};
|
||||
mipLevels = 1;
|
||||
arrayLayers = 1;
|
||||
tiling = optimal;
|
||||
usage = color_attachment|input_attachment|transient_attachment;
|
||||
initialLayout = undefined;
|
||||
};
|
||||
view_base = {
|
||||
viewType = `2d;
|
||||
components = {
|
||||
r = identity;
|
||||
g = identity;
|
||||
b = identity;
|
||||
a = identity;
|
||||
};
|
||||
subresourceRange = {
|
||||
aspectMask = color;
|
||||
levelCount = 1;
|
||||
layerCount = 1;
|
||||
};
|
||||
};
|
||||
attachment_base = {
|
||||
samples = 1;
|
||||
loadOp = dont_care;
|
||||
storeOp = dont_care;
|
||||
stencilLoadOp = dont_care;
|
||||
stencilStoreOp = dont_care;
|
||||
initialLayout = undefined;
|
||||
finalLayout = color_attachment_optimal;
|
||||
clearValue = { color = "[0, 0, 0, 1]"; };
|
||||
};
|
||||
};
|
||||
images = {
|
||||
depth = {
|
||||
@inherit = image_base;
|
||||
format = x8_d24_unorm_pack32;
|
||||
usage = depth_stencil_attachment|input_attachment|transient_attachment;
|
||||
};
|
||||
color = {
|
||||
@inherit = image_base;
|
||||
format = r8g8b8a8_unorm;
|
||||
};
|
||||
emission = {
|
||||
@inherit = image_base;
|
||||
format = r16g16b16a16_sfloat;
|
||||
};
|
||||
normal = {
|
||||
@inherit = image_base;
|
||||
format = r16g16b16a16_sfloat;
|
||||
};
|
||||
position = {
|
||||
@inherit = image_base;
|
||||
format = r32g32b32a32_sfloat;
|
||||
};
|
||||
opaque = {
|
||||
@inherit = image_base;
|
||||
format = r16g16b16a16_sfloat;
|
||||
};
|
||||
};
|
||||
views = {
|
||||
depth = {
|
||||
@inherit = view_base;
|
||||
image = depth;
|
||||
format = $images.depth.format;
|
||||
subresourceRange = {
|
||||
aspectMask = depth;
|
||||
};
|
||||
};
|
||||
color = {
|
||||
@inherit = view_base;
|
||||
image = color;
|
||||
format = $images.color.format;
|
||||
};
|
||||
emission = {
|
||||
@inherit = view_base;
|
||||
image = color;
|
||||
format = $images.color.format;
|
||||
};
|
||||
normal = {
|
||||
@inherit = view_base;
|
||||
image = color;
|
||||
format = $images.color.format;
|
||||
};
|
||||
position = {
|
||||
@inherit = view_base;
|
||||
image = color;
|
||||
format = $images.color.format;
|
||||
};
|
||||
opaque = {
|
||||
@inherit = view_base;
|
||||
image = color;
|
||||
format = $images.color.format;
|
||||
};
|
||||
output = {
|
||||
@inherit = view_base;
|
||||
image = $output.image;
|
||||
format = $output.format;
|
||||
}
|
||||
};
|
||||
renderpasses = {
|
||||
deferred = {
|
||||
attachments = {
|
||||
depth = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.depth.format;
|
||||
loadOp = clear;
|
||||
finalLayout = depth_stencil_attachment_optimal;
|
||||
clearValue = { depthStencil = { depth = 1; stencil = 0; }; };
|
||||
};
|
||||
color = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.color.format;
|
||||
loadOp = clear;
|
||||
finalLayout = depth_stencil_attachment_optimal;
|
||||
};
|
||||
emission = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.emission.format;
|
||||
loadOp = clear;
|
||||
};
|
||||
normal = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.normal.format;
|
||||
};
|
||||
position = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.position.format;
|
||||
};
|
||||
opaque = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.opaque.format;
|
||||
};
|
||||
output = {
|
||||
@inherit = $attachment_base;
|
||||
format = $images.output.format;
|
||||
loadOp = clear;
|
||||
storeOp = store;
|
||||
$output.finalLayout;
|
||||
};
|
||||
};
|
||||
framebuffer = {
|
||||
attachments = (depth, color, emission, normal, position, opaque,
|
||||
$output.view);
|
||||
width = $output.extent.width;
|
||||
height = $output.extent.height;
|
||||
layers = 1;
|
||||
};
|
||||
subpasses = {
|
||||
depth = {
|
||||
color = "[ 0.5, 0.5, 0.5, 1]";
|
||||
attachments = {
|
||||
depth = depth_stencil_read_only_optimal;
|
||||
preserve = (color, emission, normal, position, output);
|
||||
};
|
||||
pipelines = {
|
||||
bsp:depth = {
|
||||
color = $color.bsp;
|
||||
pipeline = bsp_depth;
|
||||
tasks = (
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, solid); },
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, sky); },
|
||||
);
|
||||
};
|
||||
alias:depth = {
|
||||
color = $color.alias;
|
||||
pipeline = alias_depth;
|
||||
tasks = (
|
||||
{ func = "alias_draw"; },
|
||||
);
|
||||
};
|
||||
iqm:depth = {
|
||||
color = $color.iqm;
|
||||
pipeline = iqm_depth;
|
||||
tasks = (
|
||||
{ func = "iqm_draw"; },
|
||||
);
|
||||
};
|
||||
sprite:depth = {
|
||||
color = $color.sprite;
|
||||
pipeline = sprite_depth;
|
||||
tasks = (
|
||||
{ func = "sprite_draw"; },
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
translucent = {
|
||||
color = "[ 0.25, 0.25, 0.6, 1]";
|
||||
depend = {
|
||||
depth = $depth_dependency;
|
||||
}
|
||||
attachments = {
|
||||
depth = depth_stencil_read_only_optimal;
|
||||
preserve = (color, emission, normal, position, output);
|
||||
};
|
||||
pipelines = {
|
||||
bsp:sky = {
|
||||
color = $color.bsp;
|
||||
pipeline = $bsp_sky_pipeline;
|
||||
tasks = (
|
||||
// FIXME sky should not use OIT
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, sky); },
|
||||
);
|
||||
};
|
||||
bsp:trans = {
|
||||
color = $color.bsp;
|
||||
pipeline = bsp_turb;
|
||||
tasks = (
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, translucent); },
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, turbulent); },
|
||||
);
|
||||
};
|
||||
particles:trans {
|
||||
color = $color.particles;
|
||||
pipline = partdraw;
|
||||
{ func = particles_draw; },
|
||||
};
|
||||
};
|
||||
};
|
||||
gbuffer = {
|
||||
color = "[ 0.3, 0.7, 0.3, 1]";
|
||||
depend = {
|
||||
depth = $depth_dependency;
|
||||
}
|
||||
attachments = {
|
||||
color = {
|
||||
color = color_attachment_optimal;
|
||||
emission = color_attachment_optimal;
|
||||
normal = color_attachment_optimal;
|
||||
position = color_attachment_optimal;
|
||||
};
|
||||
depth = depth_stencil_read_only_optimal;
|
||||
preserve = (output);
|
||||
};
|
||||
pipelines = {
|
||||
bsp:gbuffer = {
|
||||
color = $color.bsp;
|
||||
pipeline = bsp_gbuf;
|
||||
tasks = (
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, solid); },
|
||||
{ func = bsp_draw_queue;
|
||||
params = (main, sky); },
|
||||
);
|
||||
};
|
||||
alias:gbuffer = {
|
||||
color = $color.alias;
|
||||
pipeline = alias_gbuf;
|
||||
tasks = (
|
||||
{ func = "alias_draw"; },
|
||||
);
|
||||
};
|
||||
iqm:gbuffer = {
|
||||
color = $color.iqm;
|
||||
pipeline = iqm_gbuf;
|
||||
tasks = (
|
||||
{ func = "iqm_draw"; },
|
||||
);
|
||||
};
|
||||
sprite:gbuffer = {
|
||||
color = $color.sprite;
|
||||
pipeline = sprite_gbuf;
|
||||
tasks = (
|
||||
{ func = "sprite_draw"; },
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
lighting = {
|
||||
color = "[ 0.8, 0.8, 0.8, 1]";
|
||||
depend = {
|
||||
gbuffer = $color_dependency;
|
||||
}
|
||||
attachments = {
|
||||
input = {
|
||||
depth = shader_read_only_optimal;
|
||||
color = shader_read_only_optimal;
|
||||
emission = shader_read_only_optimal;
|
||||
normal = shader_read_only_optimal;
|
||||
position = shader_read_only_optimal;
|
||||
};
|
||||
color = {
|
||||
opaque = color_attachment_optimal;
|
||||
};
|
||||
preserve = (output);
|
||||
};
|
||||
pipelines = {
|
||||
lights = {
|
||||
color = $color.lights
|
||||
pipeline = lighting;
|
||||
tasks = (
|
||||
{ func = "lights_draw"; },
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
compose = {
|
||||
color = "[ 0.7, 0.3, 0.3, 1]";
|
||||
depend = {
|
||||
lighting = $color_dependency;
|
||||
}
|
||||
attachments = {
|
||||
input = {
|
||||
opaque = shader_read_only_optimal;
|
||||
};
|
||||
color = {
|
||||
output = color_attachment_optimal;
|
||||
};
|
||||
preserve = (depth, color, emission, normal, position);
|
||||
};
|
||||
pipelines = {
|
||||
compose = {
|
||||
color = $color.compose
|
||||
pipeline = compose;
|
||||
tasks = (
|
||||
{ func = "lights_draw"; },
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
deferred_cube = {
|
||||
@inherit = deferred;
|
||||
@next = (VkRenderPassMultiviewCreateInfo, {
|
||||
viewMasks = (0x3fu, 0x3fu, 0x3fu, 0x3fu, 0x3fu);
|
||||
viewOffsets = ( 0, 0, 0, 0, 0);
|
||||
});
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue