-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVKRenderPass.cpp
More file actions
96 lines (78 loc) · 4.25 KB
/
VKRenderPass.cpp
File metadata and controls
96 lines (78 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "VKPCH.h"
size_t RenderPassCounter = 0;
VKRenderPass::VKRenderPass(const BearRenderPassDescription& description)
{
RenderPassCounter++;
Description = description;
CountRenderTarget = 0;
for (; description.RenderTargets[CountRenderTarget].Format != BearRenderTargetFormat::None && CountRenderTarget < 8; CountRenderTarget++) {}
VkAttachmentReference AttachmentReference[8] = {};
VkAttachmentReference DepthAttachmentReference = {};
DepthAttachmentReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkAttachmentDescription AttachmentDescription[9] = {};
VkSubpassDescription SubpassDescription = {};
for (size_t i = 0; i < CountRenderTarget; i++)
{
AttachmentDescription[i].format = VKFactory::Translation(description.RenderTargets[i].Format);
AttachmentDescription[i].samples = VK_SAMPLE_COUNT_1_BIT;
AttachmentDescription[i].loadOp = description.RenderTargets[i].Clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
AttachmentDescription[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
AttachmentDescription[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
AttachmentDescription[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
AttachmentDescription[i].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
AttachmentDescription[i].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
AttachmentDescription[i].flags = 0;
AttachmentReference[i].attachment = static_cast<uint32_t>(i);
AttachmentReference[i].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
SubpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
SubpassDescription.flags = 0;
SubpassDescription.inputAttachmentCount = 0;
SubpassDescription.pInputAttachments = NULL;
SubpassDescription.colorAttachmentCount = static_cast<uint32_t>(CountRenderTarget); ;
SubpassDescription.pColorAttachments = AttachmentReference;
SubpassDescription.pResolveAttachments = NULL;
SubpassDescription.pDepthStencilAttachment = NULL;
SubpassDescription.preserveAttachmentCount = 0;
SubpassDescription.pPreserveAttachments = NULL;
VkRenderPassCreateInfo RenderPassCreateInfo = {};
RenderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
RenderPassCreateInfo.pNext = NULL;
RenderPassCreateInfo.attachmentCount = static_cast<uint32_t>(CountRenderTarget); ;
RenderPassCreateInfo.pAttachments = AttachmentDescription;
RenderPassCreateInfo.subpassCount = 1;
RenderPassCreateInfo.pSubpasses = &SubpassDescription;
RenderPassCreateInfo.dependencyCount = 0;
RenderPassCreateInfo.pDependencies = NULL;
if (description.DepthStencil.Format != BearDepthStencilFormat::None)
{
AttachmentDescription[CountRenderTarget].format = VKFactory::Translation(description.DepthStencil.Format);
AttachmentDescription[CountRenderTarget].samples = VK_SAMPLE_COUNT_1_BIT;
AttachmentDescription[CountRenderTarget].loadOp = description.DepthStencil.Clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
AttachmentDescription[CountRenderTarget].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
switch (description.DepthStencil.Format)
{
case BearDepthStencilFormat::Depth24Stencil8:
case BearDepthStencilFormat::Depth32FStencil8:
AttachmentDescription[CountRenderTarget].stencilLoadOp = description.DepthStencil.Clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
AttachmentDescription[CountRenderTarget].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
break;
default:
AttachmentDescription[CountRenderTarget].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
AttachmentDescription[CountRenderTarget].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
break;
}
AttachmentDescription[CountRenderTarget].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
AttachmentDescription[CountRenderTarget].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
AttachmentDescription[CountRenderTarget].flags = 0;
RenderPassCreateInfo.attachmentCount++;
SubpassDescription.pDepthStencilAttachment = &DepthAttachmentReference;
DepthAttachmentReference.attachment = static_cast<uint32_t>(CountRenderTarget); ;
}
V_CHK(vkCreateRenderPass(Factory->Device, &RenderPassCreateInfo, NULL, &RenderPass));
}
VKRenderPass::~VKRenderPass()
{
vkDestroyRenderPass(Factory->Device, RenderPass, 0);
RenderPassCounter--;
}