mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-06-01 09:02:08 +00:00
[vulkan] Get water warp and fisheye mostly working
Water warp works quite well, but fisheye is having a little trouble (current issue is framebuffer size mismatch).
This commit is contained in:
parent
ab4ea1b333
commit
7ba347cb6c
2 changed files with 285 additions and 34 deletions
|
@ -50,6 +50,15 @@ properties = {
|
||||||
usage = color_attachment|input_attachment|transient_attachment;
|
usage = color_attachment|input_attachment|transient_attachment;
|
||||||
initialLayout = undefined;
|
initialLayout = undefined;
|
||||||
};
|
};
|
||||||
|
cube_image_base = {
|
||||||
|
@inherit = $image_base;
|
||||||
|
extent = {
|
||||||
|
width = "min($render_output.extent.width,$render_output.extent.height)";
|
||||||
|
height = "min($render_output.extent.width,$render_output.extent.height)";
|
||||||
|
depth = 1;
|
||||||
|
};
|
||||||
|
arrayLayers = 6;
|
||||||
|
};
|
||||||
view_base = {
|
view_base = {
|
||||||
viewType = `2d;
|
viewType = `2d;
|
||||||
components = {
|
components = {
|
||||||
|
@ -64,6 +73,13 @@ properties = {
|
||||||
layerCount = 1;
|
layerCount = 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
cube_view_base = {
|
||||||
|
@inherit = $view_base;
|
||||||
|
viewType = `2d_array;
|
||||||
|
subresourceRange = {
|
||||||
|
layerCount = 6;
|
||||||
|
};
|
||||||
|
};
|
||||||
attachment_base = {
|
attachment_base = {
|
||||||
samples = 1;
|
samples = 1;
|
||||||
loadOp = dont_care;
|
loadOp = dont_care;
|
||||||
|
@ -494,6 +510,11 @@ properties = {
|
||||||
name = main;
|
name = main;
|
||||||
module = $builtin/fstriangle.vert;
|
module = $builtin/fstriangle.vert;
|
||||||
};
|
};
|
||||||
|
vertexst = {
|
||||||
|
stage = vertex;
|
||||||
|
name = main;
|
||||||
|
module = $builtin/fstrianglest.vert;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
lighting = {
|
lighting = {
|
||||||
|
@ -880,6 +901,37 @@ images = {
|
||||||
usage = color_attachment|input_attachment|sampled;
|
usage = color_attachment|input_attachment|sampled;
|
||||||
format = $render_output.format;
|
format = $render_output.format;
|
||||||
};
|
};
|
||||||
|
cube_depth = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
format = x8_d24_unorm_pack32;
|
||||||
|
usage = depth_stencil_attachment|input_attachment|transient_attachment;
|
||||||
|
};
|
||||||
|
cube_color = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
format = r8g8b8a8_unorm;
|
||||||
|
};
|
||||||
|
cube_emission = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
format = r16g16b16a16_sfloat;
|
||||||
|
};
|
||||||
|
cube_normal = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
format = r16g16b16a16_sfloat;
|
||||||
|
};
|
||||||
|
cube_position = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
format = r32g32b32a32_sfloat;
|
||||||
|
};
|
||||||
|
cube_opaque = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
format = r16g16b16a16_sfloat;
|
||||||
|
};
|
||||||
|
cube_output = {
|
||||||
|
@inherit = $cube_image_base;
|
||||||
|
flags = cube_compatible;
|
||||||
|
usage = color_attachment|input_attachment|sampled;
|
||||||
|
format = $render_output.format;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
imageviews = {
|
imageviews = {
|
||||||
depth = {
|
depth = {
|
||||||
|
@ -919,7 +971,46 @@ imageviews = {
|
||||||
@inherit = $view_base;
|
@inherit = $view_base;
|
||||||
image = output;
|
image = output;
|
||||||
format = $render_output.format;
|
format = $render_output.format;
|
||||||
}
|
};
|
||||||
|
cube_depth = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
image = cube_depth;
|
||||||
|
format = $images.cube_depth.format;
|
||||||
|
subresourceRange = {
|
||||||
|
aspectMask = depth;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
cube_color = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
image = cube_color;
|
||||||
|
format = $images.cube_color.format;
|
||||||
|
};
|
||||||
|
cube_emission = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
image = cube_emission;
|
||||||
|
format = $images.cube_emission.format;
|
||||||
|
};
|
||||||
|
cube_normal = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
image = cube_normal;
|
||||||
|
format = $images.cube_normal.format;
|
||||||
|
};
|
||||||
|
cube_position = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
image = cube_position;
|
||||||
|
format = $images.cube_position.format;
|
||||||
|
};
|
||||||
|
cube_opaque = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
image = cube_opaque;
|
||||||
|
format = $images.cube_opaque.format;
|
||||||
|
};
|
||||||
|
cube_output = {
|
||||||
|
@inherit = $cube_view_base;
|
||||||
|
viewType = cube;
|
||||||
|
image = cube_output;
|
||||||
|
format = $render_output.format;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
output = {
|
output = {
|
||||||
view = $output;
|
view = $output;
|
||||||
|
@ -1334,6 +1425,56 @@ renderpasses = {
|
||||||
viewMasks = (0x3fu, 0x3fu, 0x3fu, 0x3fu, 0x3fu);
|
viewMasks = (0x3fu, 0x3fu, 0x3fu, 0x3fu, 0x3fu);
|
||||||
viewOffsets = ( 0, 0, 0, 0, 0);
|
viewOffsets = ( 0, 0, 0, 0, 0);
|
||||||
});
|
});
|
||||||
|
framebuffer = {
|
||||||
|
width = $render_output.extent.width;
|
||||||
|
height = $render_output.extent.height;
|
||||||
|
layers = 1;
|
||||||
|
attachments = {
|
||||||
|
depth = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $images.cube_depth.format;
|
||||||
|
loadOp = clear;
|
||||||
|
finalLayout = depth_stencil_attachment_optimal;
|
||||||
|
clearValue = { depthStencil = { depth = 1; stencil = 0; }; };
|
||||||
|
view = cube_depth;
|
||||||
|
};
|
||||||
|
color = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $images.cube_color.format;
|
||||||
|
loadOp = clear;
|
||||||
|
view = cube_color;
|
||||||
|
};
|
||||||
|
emission = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $images.cube_emission.format;
|
||||||
|
loadOp = clear;
|
||||||
|
view = cube_emission;
|
||||||
|
};
|
||||||
|
normal = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $images.cube_normal.format;
|
||||||
|
view = cube_normal;
|
||||||
|
};
|
||||||
|
position = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $images.cube_position.format;
|
||||||
|
view = cube_position;
|
||||||
|
};
|
||||||
|
opaque = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $images.cube_opaque.format;
|
||||||
|
view = cube_opaque;
|
||||||
|
};
|
||||||
|
output = {
|
||||||
|
@inherit = $attachment_base;
|
||||||
|
format = $render_output.format;
|
||||||
|
loadOp = clear;
|
||||||
|
storeOp = store;
|
||||||
|
finalLayout = $render_output.finalLayout;
|
||||||
|
view = cube_output;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
output = {
|
output = {
|
||||||
color = "[0, 1, 1, 1]";
|
color = "[0, 1, 1, 1]";
|
||||||
|
@ -1360,7 +1501,7 @@ renderpasses = {
|
||||||
|
|
||||||
color = $color.output;
|
color = $color.output;
|
||||||
tasks = (
|
tasks = (
|
||||||
{ func = output_draw; },
|
{ func = output_draw_flat; },
|
||||||
);
|
);
|
||||||
|
|
||||||
stages = (
|
stages = (
|
||||||
|
@ -1369,6 +1510,36 @@ renderpasses = {
|
||||||
);
|
);
|
||||||
layout = $output.layout;
|
layout = $output.layout;
|
||||||
};
|
};
|
||||||
|
waterwarp = {
|
||||||
|
@inherit = $compose_base;
|
||||||
|
disabled = true;
|
||||||
|
|
||||||
|
color = $color.output;
|
||||||
|
tasks = (
|
||||||
|
{ func = output_draw_waterwarp; },
|
||||||
|
);
|
||||||
|
|
||||||
|
stages = (
|
||||||
|
$fstriangle.shader.vertexst,
|
||||||
|
$waterwarp.shader.fragment,
|
||||||
|
);
|
||||||
|
layout = $waterwarp.layout;
|
||||||
|
};
|
||||||
|
fisheye = {
|
||||||
|
@inherit = $compose_base;
|
||||||
|
disabled = true;
|
||||||
|
|
||||||
|
color = $color.output;
|
||||||
|
tasks = (
|
||||||
|
{ func = output_draw_fisheye; },
|
||||||
|
);
|
||||||
|
|
||||||
|
stages = (
|
||||||
|
$fstriangle.shader.vertexst,
|
||||||
|
$fisheye.shader.fragment,
|
||||||
|
);
|
||||||
|
layout = $fisheye.layout;
|
||||||
|
};
|
||||||
slice = {
|
slice = {
|
||||||
@inherit = $compose_base;
|
@inherit = $compose_base;
|
||||||
|
|
||||||
|
@ -1471,6 +1642,8 @@ steps = {
|
||||||
dependencies = (wait_on_fence);
|
dependencies = (wait_on_fence);
|
||||||
process = {
|
process = {
|
||||||
tasks = (
|
tasks = (
|
||||||
|
{ func = output_select_renderpass;
|
||||||
|
params = ("\"main\""); },
|
||||||
{ func = update_framebuffer;
|
{ func = update_framebuffer;
|
||||||
params = ("\"main\""); },
|
params = ("\"main\""); },
|
||||||
{ func = particle_wait_physics; },
|
{ func = particle_wait_physics; },
|
||||||
|
@ -1494,6 +1667,8 @@ steps = {
|
||||||
params = ("\"output\""); },
|
params = ("\"output\""); },
|
||||||
{ func = update_input;
|
{ func = update_input;
|
||||||
params = ("\"main\""); },
|
params = ("\"main\""); },
|
||||||
|
{ func = output_select_pipeline;
|
||||||
|
params = ("\"output\""); },
|
||||||
{ func = flush_draw; },
|
{ func = flush_draw; },
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -161,9 +161,53 @@ update_input (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
output_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
output_select_pipeline (const exprval_t **params, exprval_t *result,
|
||||||
|
exprctx_t *ectx)
|
||||||
{
|
{
|
||||||
auto taskctx = (qfv_taskctx_t *) ectx;
|
auto taskctx = (qfv_taskctx_t *) ectx;
|
||||||
|
auto ctx = taskctx->ctx;
|
||||||
|
auto output = QFV_GetStep (params[0], ctx->render_context->job);
|
||||||
|
// FIXME the output render pass has only one subpass
|
||||||
|
auto sp = output->render->active->subpasses;
|
||||||
|
|
||||||
|
// FIXME the output render pass pipelines are in the order
|
||||||
|
// output, waterwarp, fisheye, followed by any additional pipelines
|
||||||
|
if (scr_fisheye) {
|
||||||
|
sp->pipelines[0].disabled = true;
|
||||||
|
sp->pipelines[1].disabled = true;
|
||||||
|
sp->pipelines[2].disabled = false;
|
||||||
|
} else if (r_dowarp) {
|
||||||
|
sp->pipelines[0].disabled = true;
|
||||||
|
sp->pipelines[1].disabled = false;
|
||||||
|
sp->pipelines[2].disabled = true;
|
||||||
|
} else {
|
||||||
|
sp->pipelines[0].disabled = false;
|
||||||
|
sp->pipelines[1].disabled = true;
|
||||||
|
sp->pipelines[2].disabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
output_select_renderpass (const exprval_t **params, exprval_t *result,
|
||||||
|
exprctx_t *ectx)
|
||||||
|
{
|
||||||
|
auto taskctx = (qfv_taskctx_t *) ectx;
|
||||||
|
auto ctx = taskctx->ctx;
|
||||||
|
auto main = QFV_GetStep (params[0], ctx->render_context->job);
|
||||||
|
// FIXME the main render step has only two renderpasses
|
||||||
|
auto render = main->render;
|
||||||
|
|
||||||
|
if (scr_fisheye) {
|
||||||
|
render->active = &render->renderpasses[1];
|
||||||
|
} else {
|
||||||
|
render->active = &render->renderpasses[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
output_draw (qfv_taskctx_t *taskctx,
|
||||||
|
int num_push_constants, qfv_push_constants_t *push_constants)
|
||||||
|
{
|
||||||
auto ctx = taskctx->ctx;
|
auto ctx = taskctx->ctx;
|
||||||
auto device = ctx->device;
|
auto device = ctx->device;
|
||||||
auto dfunc = device->funcs;
|
auto dfunc = device->funcs;
|
||||||
|
@ -172,45 +216,54 @@ output_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
||||||
auto layout = taskctx->pipeline->layout;
|
auto layout = taskctx->pipeline->layout;
|
||||||
auto cmd = taskctx->cmd;
|
auto cmd = taskctx->cmd;
|
||||||
|
|
||||||
//__auto_type pipeline = octx->output;
|
|
||||||
//if (scr_fisheye) {
|
|
||||||
// pipeline = octx->fisheye;
|
|
||||||
// layout = octx->fish_layout;
|
|
||||||
//} else if (r_dowarp) {
|
|
||||||
// pipeline = octx->waterwarp;
|
|
||||||
// layout = octx->warp_layout;
|
|
||||||
//}
|
|
||||||
|
|
||||||
VkDescriptorSet set[] = {
|
VkDescriptorSet set[] = {
|
||||||
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
|
Vulkan_Matrix_Descriptors (ctx, ctx->curFrame),
|
||||||
oframe->set,
|
oframe->set,
|
||||||
};
|
};
|
||||||
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
layout, 0, 2, set, 0, 0);
|
layout, 0, 2, set, 0, 0);
|
||||||
#if 0
|
if (num_push_constants) {
|
||||||
if (scr_fisheye) {
|
QFV_PushConstants (device, cmd, layout,
|
||||||
float width = r_refdef.vrect.width;
|
num_push_constants, push_constants);
|
||||||
float height = r_refdef.vrect.height;
|
|
||||||
|
|
||||||
float ffov = scr_ffov * M_PI / 360;
|
|
||||||
float aspect = height / width;
|
|
||||||
qfv_push_constants_t push_constants[] = {
|
|
||||||
{ VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof (float), &ffov },
|
|
||||||
{ VK_SHADER_STAGE_FRAGMENT_BIT, 4, sizeof (float), &aspect },
|
|
||||||
};
|
|
||||||
QFV_PushConstants (device, cmd, layout, 2, push_constants);
|
|
||||||
} else if (r_dowarp) {
|
|
||||||
float time = vr_data.realtime;
|
|
||||||
qfv_push_constants_t push_constants[] = {
|
|
||||||
{ VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof (float), &time },
|
|
||||||
};
|
|
||||||
QFV_PushConstants (device, cmd, layout, 1, push_constants);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
dfunc->vkCmdDraw (cmd, 3, 1, 0, 0);
|
dfunc->vkCmdDraw (cmd, 3, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
output_draw_flat (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
||||||
|
{
|
||||||
|
auto taskctx = (qfv_taskctx_t *) ectx;
|
||||||
|
output_draw (taskctx, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
output_draw_waterwarp (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
||||||
|
{
|
||||||
|
auto taskctx = (qfv_taskctx_t *) ectx;
|
||||||
|
float time = vr_data.realtime;
|
||||||
|
qfv_push_constants_t push_constants[] = {
|
||||||
|
{ VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof (float), &time },
|
||||||
|
};
|
||||||
|
output_draw (taskctx, 1, push_constants);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
output_draw_fisheye (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
||||||
|
{
|
||||||
|
auto taskctx = (qfv_taskctx_t *) ectx;
|
||||||
|
float width = r_refdef.vrect.width;
|
||||||
|
float height = r_refdef.vrect.height;
|
||||||
|
|
||||||
|
float ffov = scr_ffov * M_PI / 360;
|
||||||
|
float aspect = height / width;
|
||||||
|
qfv_push_constants_t push_constants[] = {
|
||||||
|
{ VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof (float), &ffov },
|
||||||
|
{ VK_SHADER_STAGE_FRAGMENT_BIT, 4, sizeof (float), &aspect },
|
||||||
|
};
|
||||||
|
output_draw (taskctx, 2, push_constants);
|
||||||
|
}
|
||||||
|
|
||||||
static exprtype_t *stepref_param[] = {
|
static exprtype_t *stepref_param[] = {
|
||||||
&cexpr_string,
|
&cexpr_string,
|
||||||
};
|
};
|
||||||
|
@ -222,14 +275,37 @@ static exprfunc_t update_input_func[] = {
|
||||||
{ .func = update_input, .num_params = 1, .param_types = stepref_param },
|
{ .func = update_input, .num_params = 1, .param_types = stepref_param },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
static exprfunc_t output_draw_func[] = {
|
static exprfunc_t output_select_pipeline_func[] = {
|
||||||
{ .func = output_draw },
|
{ .func = output_select_pipeline,
|
||||||
|
.num_params = 1, .param_types = stepref_param },
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
static exprfunc_t output_select_renderpass_func[] = {
|
||||||
|
{ .func = output_select_renderpass,
|
||||||
|
.num_params = 1, .param_types = stepref_param },
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
static exprfunc_t output_draw_flat_func[] = {
|
||||||
|
{ .func = output_draw_flat },
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
static exprfunc_t output_draw_waterwarp_func[] = {
|
||||||
|
{ .func = output_draw_waterwarp },
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
static exprfunc_t output_draw_fisheye_func[] = {
|
||||||
|
{ .func = output_draw_fisheye },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
static exprsym_t output_task_syms[] = {
|
static exprsym_t output_task_syms[] = {
|
||||||
{ "acquire_output", &cexpr_function, acquire_output_func },
|
{ "acquire_output", &cexpr_function, acquire_output_func },
|
||||||
{ "update_input", &cexpr_function, update_input_func },
|
{ "update_input", &cexpr_function, update_input_func },
|
||||||
{ "output_draw", &cexpr_function, output_draw_func },
|
{ "output_select_pipeline", &cexpr_function, output_select_pipeline_func },
|
||||||
|
{ "output_select_renderpass", &cexpr_function,
|
||||||
|
output_select_renderpass_func },
|
||||||
|
{ "output_draw_flat", &cexpr_function, output_draw_flat_func },
|
||||||
|
{ "output_draw_waterwarp", &cexpr_function, output_draw_waterwarp_func },
|
||||||
|
{ "output_draw_fisheye", &cexpr_function, output_draw_fisheye_func },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue