FCT
载入中...
搜索中...
未找到
VK_Pass.cpp
浏览该文件的文档.
1//
2// Created by Administrator on 2025/3/28.
3//
4
5#include "./VK_Pass.h"
6#include "./VK_PassGroup.h"
9namespace FCT
10{
11 namespace RHI
12 {
14 {
15 m_ctx = ctx;
16 m_group = nullptr;
17 }
18
20 {
21 }
22
23 void VK_Pass::create(PassGroup* srcGroup)
24 {
25 auto group = static_cast<VK_PassGroup*>(srcGroup);
26 m_desc.pipelineBindPoint = vk::PipelineBindPoint::eGraphics;
27
28 if (!m_renderTargets.empty()) {
29 uint32_t maxSlot = m_renderTargets.rbegin()->first;
30
31 m_renderTargetRefs.resize(maxSlot + 1);
32
33 for (auto& ref : m_renderTargetRefs) {
34 ref.attachment = VK_ATTACHMENT_UNUSED;
35 ref.layout = vk::ImageLayout::eUndefined;
36 }
37
38 for (const auto& [slot, target] : m_renderTargets) {
39 vk::AttachmentReference& ref = m_renderTargetRefs[slot];
40 ref.attachment = m_targetAttachmentIndices[slot];
41 ref.layout = vk::ImageLayout::eColorAttachmentOptimal;
42 }
43
44 m_desc.colorAttachmentCount = maxSlot + 1;
45 m_desc.pColorAttachments = m_renderTargetRefs.data();
46 } else {
47 m_desc.colorAttachmentCount = 0;
48 m_desc.pColorAttachments = nullptr;
49 }
50
51 if (m_depthStencil) {
53 m_depthStencilRef.layout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
54
55 m_desc.pDepthStencilAttachment = &m_depthStencilRef;
56
57 fout << "Pass using depth stencil attachment with index: "
58 << m_depthStencilAttachmentIndex << std::endl;
59 } else {
60 m_desc.pDepthStencilAttachment = nullptr;
61 }
62
63 m_group = group;
64 }
65
66
68 {
69 if (!m_clearValue.types) {
70 return;
71 }
72
73 auto vkCmdBuf = static_cast<VK_CommandBuffer*>(cmdBuf);
74 std::vector<vk::ClearAttachment> clearAttachments;
75
76 if (m_clearValue.types & ClearType::color) {
77 for (const auto& [slot, attachmentIndex] : m_targetAttachmentIndices) {
78 if (slot < m_renderTargetRefs.size() && m_renderTargetRefs[slot].attachment != VK_ATTACHMENT_UNUSED) {
79 vk::ClearAttachment clearAttachment;
80 clearAttachment.aspectMask = vk::ImageAspectFlagBits::eColor;
81 clearAttachment.colorAttachment = slot;
82 clearAttachment.clearValue.color = vk::ClearColorValue(std::array<float, 4>{
83 m_clearValue.color.x,
84 m_clearValue.color.y,
85 m_clearValue.color.z,
86 m_clearValue.color.w
87 });
88 clearAttachments.push_back(clearAttachment);
89 }
90 }
91 }
92
93 if (m_depthStencil && m_depthStencilAttachmentIndex != UINT32_MAX &&
95
96 vk::ClearAttachment clearAttachment;
97 clearAttachment.aspectMask = vk::ImageAspectFlagBits::eNone;
98
99 if (m_clearValue.types & ClearType::depth) {
100 clearAttachment.aspectMask |= vk::ImageAspectFlagBits::eDepth;
101 }
102
103 if (m_clearValue.types & ClearType::stencil) {
104 clearAttachment.aspectMask |= vk::ImageAspectFlagBits::eStencil;
105 }
106
107 clearAttachment.clearValue.depthStencil = vk::ClearDepthStencilValue(
108 m_clearValue.depth,
109 m_clearValue.stencil
110 );
111
112 clearAttachments.push_back(clearAttachment);
113 }
114
115 if (!clearAttachments.empty()) {
116 vk::ClearRect clearRect;
117 clearRect.rect.offset = vk::Offset2D(0, 0);
118
119 uint32_t width = 0, height = 0;
120 if (!m_renderTargets.empty()) {
121 auto& firstTarget = m_renderTargets.begin()->second;
122 width = firstTarget->width();
123 height = firstTarget->height();
124 } else if (m_depthStencil) {
125 width = m_depthStencil->width();
126 height = m_depthStencil->height();
127 }
128
129 clearRect.rect.extent = vk::Extent2D(width, height);
130 clearRect.baseArrayLayer = 0;
131 clearRect.layerCount = 1;
132
133 vkCmdBuf->commandBuffer().clearAttachments(clearAttachments, clearRect);
134 }
135 }
136
138 {
139
140 }
141
143 {
144 if (!m_clearValue.types) {
145 return;
146 }
147
148 auto vkCmdBuf = static_cast<VK_CommandBuffer*>(cmdBuf);
149 std::vector<vk::ClearAttachment> clearAttachments;
150
151 if (m_clearValue.types & ClearType::color) {
152 for (const auto& [slot, attachmentIndex] : m_targetAttachmentIndices) {
153 if (slot < m_renderTargetRefs.size() && m_renderTargetRefs[slot].attachment != VK_ATTACHMENT_UNUSED) {
154 vk::ClearAttachment clearAttachment;
155 clearAttachment.aspectMask = vk::ImageAspectFlagBits::eColor;
156 clearAttachment.colorAttachment = slot;
157 clearAttachment.clearValue.color = vk::ClearColorValue(std::array<float, 4>{
158 m_clearValue.color.x,
159 m_clearValue.color.y,
160 m_clearValue.color.z,
161 m_clearValue.color.w
162 });
163 clearAttachments.push_back(clearAttachment);
164 }
165 }
166 }
167
168 if (m_depthStencil && m_depthStencilAttachmentIndex != UINT32_MAX &&
170
171 vk::ClearAttachment clearAttachment;
172 clearAttachment.aspectMask = vk::ImageAspectFlagBits::eNone;
173
174 if (m_clearValue.types & ClearType::depth) {
175 clearAttachment.aspectMask |= vk::ImageAspectFlagBits::eDepth;
176 }
177
178 if (m_clearValue.types & ClearType::stencil) {
179 clearAttachment.aspectMask |= vk::ImageAspectFlagBits::eStencil;
180 }
181
182 clearAttachment.clearValue.depthStencil = vk::ClearDepthStencilValue(
183 m_clearValue.depth,
184 m_clearValue.stencil
185 );
186
187 clearAttachments.push_back(clearAttachment);
188 }
189
190 if (!clearAttachments.empty()) {
191 vk::ClearRect clearRect;
192 clearRect.rect.offset = vk::Offset2D(0, 0);
193
194 uint32_t width = 0, height = 0;
195 if (!m_renderTargets.empty()) {
196 auto& firstTarget = m_renderTargets.begin()->second;
197 width = firstTarget->width();
198 height = firstTarget->height();
199 } else if (m_depthStencil) {
200 width = m_depthStencil->width();
201 height = m_depthStencil->height();
202 }
203
204 clearRect.rect.extent = vk::Extent2D(width, height);
205 clearRect.baseArrayLayer = 0;
206 clearRect.layerCount = 1;
207
208 vkCmdBuf->commandBuffer().clearAttachments(clearAttachments, clearRect);
209 }
210 }
211 }
212}
PassClearValue m_clearValue
定义 Pass.h:90
std::map< uint32_t, FCT::Image * > m_renderTargets
定义 Pass.h:88
FCT::Image * m_depthStencil
定义 Pass.h:84
PassGroup * m_group
定义 Pass.h:85
PassGroup * group() const
定义 Pass.h:79
void executeClear(CommandBuffer *cmdBuf) override
uint32_t m_depthStencilAttachmentIndex
VK_Pass(VK_Context *ctx)
std::map< uint32_t, uint32_t > m_targetAttachmentIndices
vk::AttachmentReference m_depthStencilRef
vk::SubpassDescription m_desc
std::vector< vk::AttachmentReference > m_renderTargetRefs
VK_Context * m_ctx
void create(PassGroup *group) override
void beginSubmit(CommandBuffer *cmdBuf) override
void endSubmit() override
std::ostream & fout