GlistEngine
Loading...
Searching...
No Matches
gVKRenderTarget.h
Go to the documentation of this file.
1/*
2 * gVKRenderTarget.h
3 *
4 * Render pass and framebuffers of the Vulkan backend. The render pass is what
5 * actually clears the screen: its colour attachment uses a CLEAR load operation,
6 * so the clear value handed to vkCmdBeginRenderPass is written by the GPU.
7 * Created by: Anil Emre Akkoc.
8 */
9
10#pragma once
11
12#ifndef CORE_GVKRENDERTARGET_H
13#define CORE_GVKRENDERTARGET_H
14
15#include "gVKContext.h"
16
17#ifdef GVK_VULKAN
18
19/*
20 * Picks a depth format the physical device supports as a depth-stencil attachment,
21 * preferring the cheapest one that is enough: D32_SFLOAT, then D32_SFLOAT_S8_UINT,
22 * then D24_UNORM_S8_UINT. Returns VK_FORMAT_UNDEFINED if the device supports none
23 * of them, which no desktop driver does in practice.
24 */
25VkFormat gvkFindDepthFormat(gVKContext& ctx);
26
27/*
28 * Creates one depth image per frame in flight, sized to the current swapchain
29 * extent. Private frame slots avoid overlapping writes without allocating one
30 * depth image for every swapchain colour image. The images carry the context's
31 * sample count: every attachment of a subpass has to agree on it, so switching the
32 * screen pass to MSAA multisamples depth as well.
33 */
34bool gvkCreateDepthResources(gVKContext& ctx);
35void gvkDestroyDepthResources(gVKContext& ctx);
36
37/*
38 * Creates the multisampled colour attachment the screen pass renders into while
39 * MSAA is on, one per frame in flight alongside the depth images. A no-op that
40 * simply reports success when the context's sample count is 1, where the swapchain
41 * image is rendered into directly. Must be called after gvkCreateRenderPass, which
42 * is where the sample count is resolved, and before gvkCreateFramebuffers.
43 */
44bool gvkCreateMsaaColorResources(gVKContext& ctx);
45void gvkDestroyMsaaColorResources(gVKContext& ctx);
46
47/*
48 * Creates the single subpass render pass used by the backend. Depends on
49 * ctx.swapchainformat, so the swapchain has to exist first. The pass carries a
50 * colour and a depth attachment; the depth one is cleared on load and discarded on
51 * store, since nothing reads it after the frame.
52 *
53 * This is also where the requested sample count is resolved against what the device
54 * supports and written to the context. With MSAA on, the pass gains a third
55 * attachment - the acquired swapchain image as the resolve target - and builds a
56 * second, single-sampled pass as the compatibility template the offscreen pipelines
57 * are built against. See gVKContext.h for why the two exist.
58 */
59bool gvkCreateRenderPass(gVKContext& ctx);
60void gvkDestroyRenderPass(gVKContext& ctx);
61
62/*
63 * Creates one framebuffer per frame-slot/swapchain-image pair, pairing any acquired
64 * colour image with that frame slot's private depth view. A resize
65 * rebuilds the framebuffers while the render pass stays valid, because neither the
66 * surface format nor the depth format changes.
67 */
68bool gvkCreateFramebuffers(gVKContext& ctx);
69void gvkDestroyFramebuffers(gVKContext& ctx);
70
71#endif /* GVK_VULKAN */
72
73#endif /* CORE_GVKRENDERTARGET_H */