diff --git a/include/QF/Vulkan/render.h b/include/QF/Vulkan/render.h index db79fbc7c..5f6071d4a 100644 --- a/include/QF/Vulkan/render.h +++ b/include/QF/Vulkan/render.h @@ -211,6 +211,7 @@ typedef struct qfv_renderpassinfo_s { qfv_framebufferinfo_t framebuffer; uint32_t num_subpasses; qfv_subpassinfo_t *subpasses; + qfv_reference_t output; } qfv_renderpassinfo_t; typedef struct qfv_computeinfo_s { @@ -320,6 +321,8 @@ typedef struct qfv_renderpass_s { qfv_framebuffer_t framebuffer; qfv_framebufferinfo_t *framebufferinfo; + VkImageView output; + qfv_reference_t outputref; } qfv_renderpass_t; typedef struct qfv_render_s { diff --git a/libs/video/renderer/vulkan/render.c b/libs/video/renderer/vulkan/render.c index 167b1727c..f30d26009 100644 --- a/libs/video/renderer/vulkan/render.c +++ b/libs/video/renderer/vulkan/render.c @@ -317,6 +317,9 @@ QFV_CreateFramebuffer (vulkan_ctx_t *ctx, qfv_renderpass_t *rp) } } else { attachments[i] = find_imageview (&fb->attachments[i].view, rctx); + if (rp->outputref.name) { + rp->output = find_imageview (&rp->outputref, rctx); + } } } @@ -457,7 +460,6 @@ QFV_Render_Shutdown (vulkan_ctx_t *ctx) __auto_type rctx = ctx->render_context; if (rctx->job) { __auto_type job = rctx->job; - //QFV_DestroyFramebuffer (ctx); //FIXME do properly for (uint32_t i = 0; i < job->num_renderpasses; i++) { dfunc->vkDestroyRenderPass (device->dev, job->renderpasses[i], 0); } diff --git a/libs/video/renderer/vulkan/render_load.c b/libs/video/renderer/vulkan/render_load.c index d2cec54cc..1e284f544 100644 --- a/libs/video/renderer/vulkan/render_load.c +++ b/libs/video/renderer/vulkan/render_load.c @@ -800,8 +800,12 @@ init_renderpass (qfv_renderpass_t *rp, qfv_renderpassinfo_t *rpinfo, .subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, .subpass_count = rpinfo->num_subpasses, .subpasses = &jp->subpasses[s->inds.num_subpasses], - .framebuffer.views = &jp->attachment_views[s->inds.num_attachments], + .framebuffer = { + .num_attachments = rpinfo->framebuffer.num_attachments, + .views = &jp->attachment_views[s->inds.num_attachments], + }, .framebufferinfo = &rpinfo->framebuffer, + .outputref = rpinfo->output, }; s->inds.num_attachments += rpinfo->framebuffer.num_attachments; for (uint32_t i = 0; i < rpinfo->num_subpasses; i++) { diff --git a/libs/video/renderer/vulkan/rp_main_def.plist b/libs/video/renderer/vulkan/rp_main_def.plist index dcecf51bd..2b229b51b 100644 --- a/libs/video/renderer/vulkan/rp_main_def.plist +++ b/libs/video/renderer/vulkan/rp_main_def.plist @@ -1302,6 +1302,7 @@ renderpasses = { }; }; }; + output = output; }; deferred_cube = { @inherit = $renderpasses.deferred; @@ -1451,7 +1452,8 @@ steps = { tasks = ( { func = acquire_output; params = ("\"output\""); }, - { func = update_input; }, + { func = update_input; + params = ("\"main\""); }, { func = flush_draw; }, ); }; diff --git a/libs/video/renderer/vulkan/vkparse.plist b/libs/video/renderer/vulkan/vkparse.plist index 1b6fcb021..530702856 100644 --- a/libs/video/renderer/vulkan/vkparse.plist +++ b/libs/video/renderer/vulkan/vkparse.plist @@ -677,6 +677,7 @@ parse = { size = num_subpasses; values = subpasses; }; + output = auto; }; qfv_descriptorsetlayoutinfo_s = { .name = qfv_descriptorsetlayoutinfo_t; @@ -706,7 +707,6 @@ parse = { qfv_renderinfo_s = { .name = qfv_renderinfo_t; color = auto; - output = ignore; renderpasses = { type = (labeledarray, qfv_renderpassinfo_t, name); size = num_renderpasses; diff --git a/libs/video/renderer/vulkan/vulkan_output.c b/libs/video/renderer/vulkan/vulkan_output.c index 130441c65..f1d9e9c3b 100644 --- a/libs/video/renderer/vulkan/vulkan_output.c +++ b/libs/video/renderer/vulkan/vulkan_output.c @@ -70,76 +70,6 @@ preoutput_draw (qfv_orenderframe_t *rFrame) static void process_input (qfv_orenderframe_t *rFrame) { - return; - vulkan_ctx_t *ctx = rFrame->vulkan_ctx; - qfv_device_t *device = ctx->device; - qfv_devfuncs_t *dfunc = device->funcs; - outputctx_t *octx = ctx->output_context; - outputframe_t *oframe = &octx->frames.a[ctx->curFrame]; - VkCommandBuffer cmd = oframe->cmd; - - DARRAY_APPEND (&rFrame->subpassCmdSets[0], cmd); - - dfunc->vkResetCommandBuffer (cmd, 0); - VkCommandBufferInheritanceInfo inherit = { - VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0, - rFrame->renderpass->renderpass, 0, - rFrame->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); - - QFV_duCmdBeginLabel (device, cmd, "output:output"); - - __auto_type pipeline = octx->output; - __auto_type layout = octx->output_layout; - if (scr_fisheye) { - pipeline = octx->fisheye; - layout = octx->fish_layout; - } else if (r_dowarp) { - pipeline = octx->waterwarp; - layout = octx->warp_layout; - } - dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - dfunc->vkCmdSetViewport (cmd, 0, 1, &rFrame->renderpass->viewport); - dfunc->vkCmdSetScissor (cmd, 0, 1, &rFrame->renderpass->scissor); - - VkDescriptorSet set[] = { - Vulkan_Matrix_Descriptors (ctx, ctx->curFrame), - oframe->set, - }; - dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, - layout, 0, 2, set, 0, 0); - if (scr_fisheye) { - 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 }, - }; - 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); - } - - dfunc->vkCmdDraw (cmd, 3, 1, 0, 0); - - - QFV_duCmdEndLabel (device, cmd); - dfunc->vkEndCommandBuffer (cmd); - } static void @@ -266,11 +196,12 @@ update_input (const exprval_t **params, exprval_t *result, exprctx_t *ectx) auto dfunc = device->funcs; auto octx = ctx->output_context; auto oframe = &octx->frames.a[ctx->curFrame]; + auto input = QFV_GetStep (params[0], ctx->render_context->job); - if (oframe->input == octx->input) { + if (oframe->input == input->render->active->output) { return; } - oframe->input = octx->input; + oframe->input = input->render->active->output; VkDescriptorImageInfo imageInfo = { octx->sampler, oframe->input, @@ -288,6 +219,50 @@ update_input (const exprval_t **params, exprval_t *result, exprctx_t *ectx) static void output_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx) { + auto taskctx = (qfv_taskctx_t *) ectx; + auto ctx = taskctx->ctx; + auto device = ctx->device; + auto dfunc = device->funcs; + auto octx = ctx->output_context; + auto oframe = &octx->frames.a[ctx->curFrame]; + auto cmd = taskctx->cmd; + + auto layout = octx->output_layout; + //__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[] = { + Vulkan_Matrix_Descriptors (ctx, ctx->curFrame), + oframe->set, + }; + dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, + layout, 0, 2, set, 0, 0); + if (scr_fisheye) { + 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 }, + }; + 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); + } + + dfunc->vkCmdDraw (cmd, 3, 1, 0, 0); } static exprtype_t *stepref_param[] = {