6
6
7
7
#include < array>
8
8
#include < cstdint>
9
- #include < vector>
10
9
11
10
#include " fml/status.h"
12
11
#include " impeller/base/validation.h"
@@ -52,15 +51,16 @@ static vk::ClearDepthStencilValue VKClearValueFromDepthStencil(uint32_t stencil,
52
51
return value;
53
52
}
54
53
55
- static std::vector<vk::ClearValue> GetVKClearValues (
56
- const RenderTarget& target) {
57
- std::vector <vk::ClearValue> clears;
58
-
54
+ static size_t GetVKClearValues (
55
+ const RenderTarget& target,
56
+ std::array <vk::ClearValue, kMaxAttachments >& values) {
57
+ size_t offset = 0u ;
59
58
target.IterateAllColorAttachments (
60
- [&clears](size_t index , const ColorAttachment& attachment) -> bool {
61
- clears.emplace_back (VKClearValueFromColor (attachment.clear_color ));
59
+ [&values, &offset](size_t index ,
60
+ const ColorAttachment& attachment) -> bool {
61
+ values.at (offset++) = VKClearValueFromColor (attachment.clear_color );
62
62
if (attachment.resolve_texture ) {
63
- clears. emplace_back ( VKClearValueFromColor (attachment.clear_color ) );
63
+ values. at (offset++) = VKClearValueFromColor (attachment.clear_color );
64
64
}
65
65
return true ;
66
66
});
@@ -69,14 +69,13 @@ static std::vector<vk::ClearValue> GetVKClearValues(
69
69
const auto & stencil = target.GetStencilAttachment ();
70
70
71
71
if (depth.has_value ()) {
72
- clears. emplace_back ( VKClearValueFromDepthStencil (
73
- stencil ? stencil->clear_stencil : 0u , depth->clear_depth )) ;
72
+ values. at (offset++) = VKClearValueFromDepthStencil (
73
+ stencil ? stencil->clear_stencil : 0u , depth->clear_depth );
74
74
} else if (stencil.has_value ()) {
75
- clears. emplace_back ( VKClearValueFromDepthStencil (
76
- stencil->clear_stencil , depth ? depth->clear_depth : 0 .0f )) ;
75
+ values. at (offset++) = VKClearValueFromDepthStencil (
76
+ stencil->clear_stencil , depth ? depth->clear_depth : 0 .0f );
77
77
}
78
-
79
- return clears;
78
+ return offset;
80
79
}
81
80
82
81
SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass (
@@ -191,15 +190,17 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
191
190
TextureVK::Cast (*resolve_image_vk_).SetCachedRenderPass (render_pass_);
192
191
}
193
192
194
- auto clear_values = GetVKClearValues (render_target_);
193
+ std::array<vk::ClearValue, kMaxAttachments > clears;
194
+ size_t clear_count = GetVKClearValues (render_target_, clears);
195
195
196
196
vk::RenderPassBeginInfo pass_info;
197
197
pass_info.renderPass = *render_pass_;
198
198
pass_info.framebuffer = *framebuffer;
199
199
pass_info.renderArea .extent .width = static_cast <uint32_t >(target_size.width );
200
200
pass_info.renderArea .extent .height =
201
201
static_cast <uint32_t >(target_size.height );
202
- pass_info.setClearValues (clear_values);
202
+ pass_info.setPClearValues (clears.data ());
203
+ pass_info.setClearValueCount (clear_count);
203
204
204
205
command_buffer_vk_.beginRenderPass (pass_info, vk::SubpassContents::eInline);
205
206
@@ -252,34 +253,37 @@ SharedHandleVK<vk::Framebuffer> RenderPassVK::CreateVKFramebuffer(
252
253
fb_info.height = target_size.height ;
253
254
fb_info.layers = 1u ;
254
255
255
- std::vector<vk::ImageView> attachments;
256
+ std::array<vk::ImageView, kMaxAttachments > attachments;
257
+ size_t count = 0 ;
256
258
257
259
// This bit must be consistent to ensure compatibility with the pass created
258
260
// earlier. Follow this order: Color attachments, then depth-stencil, then
259
261
// stencil.
260
262
render_target_.IterateAllColorAttachments (
261
- [&attachments](size_t index , const ColorAttachment& attachment) -> bool {
263
+ [&attachments, &count](size_t index ,
264
+ const ColorAttachment& attachment) -> bool {
262
265
// The bind point doesn't matter here since that information is present
263
266
// in the render pass.
264
- attachments. emplace_back (
265
- TextureVK::Cast (*attachment.texture ).GetRenderTargetView ()) ;
267
+ attachments[count++] =
268
+ TextureVK::Cast (*attachment.texture ).GetRenderTargetView ();
266
269
if (attachment.resolve_texture ) {
267
- attachments. emplace_back ( TextureVK::Cast (*attachment.resolve_texture )
268
- .GetRenderTargetView () );
270
+ attachments[count++] = TextureVK::Cast (*attachment.resolve_texture )
271
+ .GetRenderTargetView ();
269
272
}
270
273
return true ;
271
274
});
272
275
273
276
if (auto depth = render_target_.GetDepthAttachment (); depth.has_value ()) {
274
- attachments. emplace_back (
275
- TextureVK::Cast (*depth->texture ).GetRenderTargetView ()) ;
277
+ attachments[count++] =
278
+ TextureVK::Cast (*depth->texture ).GetRenderTargetView ();
276
279
} else if (auto stencil = render_target_.GetStencilAttachment ();
277
280
stencil.has_value ()) {
278
- attachments. emplace_back (
279
- TextureVK::Cast (*stencil->texture ).GetRenderTargetView ()) ;
281
+ attachments[count++] =
282
+ TextureVK::Cast (*stencil->texture ).GetRenderTargetView ();
280
283
}
281
284
282
- fb_info.setAttachments (attachments);
285
+ fb_info.setPAttachments (attachments.data ());
286
+ fb_info.setAttachmentCount (count);
283
287
284
288
auto [result, framebuffer] =
285
289
context.GetDevice ().createFramebufferUnique (fb_info);
0 commit comments