66
77#include < array>
88#include < cstdint>
9- #include < vector>
109
1110#include " fml/status.h"
1211#include " impeller/base/validation.h"
@@ -52,15 +51,16 @@ static vk::ClearDepthStencilValue VKClearValueFromDepthStencil(uint32_t stencil,
5251 return value;
5352}
5453
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 ;
5958 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 );
6262 if (attachment.resolve_texture ) {
63- clears. emplace_back ( VKClearValueFromColor (attachment.clear_color ) );
63+ values. at (offset++) = VKClearValueFromColor (attachment.clear_color );
6464 }
6565 return true ;
6666 });
@@ -69,14 +69,13 @@ static std::vector<vk::ClearValue> GetVKClearValues(
6969 const auto & stencil = target.GetStencilAttachment ();
7070
7171 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 );
7474 } 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 );
7777 }
78-
79- return clears;
78+ return offset;
8079}
8180
8281SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass (
@@ -191,15 +190,17 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
191190 TextureVK::Cast (*resolve_image_vk_).SetCachedRenderPass (render_pass_);
192191 }
193192
194- auto clear_values = GetVKClearValues (render_target_);
193+ std::array<vk::ClearValue, kMaxAttachments > clears;
194+ size_t clear_count = GetVKClearValues (render_target_, clears);
195195
196196 vk::RenderPassBeginInfo pass_info;
197197 pass_info.renderPass = *render_pass_;
198198 pass_info.framebuffer = *framebuffer;
199199 pass_info.renderArea .extent .width = static_cast <uint32_t >(target_size.width );
200200 pass_info.renderArea .extent .height =
201201 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);
203204
204205 command_buffer_vk_.beginRenderPass (pass_info, vk::SubpassContents::eInline);
205206
@@ -252,34 +253,37 @@ SharedHandleVK<vk::Framebuffer> RenderPassVK::CreateVKFramebuffer(
252253 fb_info.height = target_size.height ;
253254 fb_info.layers = 1u ;
254255
255- std::vector<vk::ImageView> attachments;
256+ std::array<vk::ImageView, kMaxAttachments > attachments;
257+ size_t count = 0 ;
256258
257259 // This bit must be consistent to ensure compatibility with the pass created
258260 // earlier. Follow this order: Color attachments, then depth-stencil, then
259261 // stencil.
260262 render_target_.IterateAllColorAttachments (
261- [&attachments](size_t index, const ColorAttachment& attachment) -> bool {
263+ [&attachments, &count](size_t index,
264+ const ColorAttachment& attachment) -> bool {
262265 // The bind point doesn't matter here since that information is present
263266 // in the render pass.
264- attachments. emplace_back (
265- TextureVK::Cast (*attachment.texture ).GetRenderTargetView ()) ;
267+ attachments[count++] =
268+ TextureVK::Cast (*attachment.texture ).GetRenderTargetView ();
266269 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 ();
269272 }
270273 return true ;
271274 });
272275
273276 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 ();
276279 } else if (auto stencil = render_target_.GetStencilAttachment ();
277280 stencil.has_value ()) {
278- attachments. emplace_back (
279- TextureVK::Cast (*stencil->texture ).GetRenderTargetView ()) ;
281+ attachments[count++] =
282+ TextureVK::Cast (*stencil->texture ).GetRenderTargetView ();
280283 }
281284
282- fb_info.setAttachments (attachments);
285+ fb_info.setPAttachments (attachments.data ());
286+ fb_info.setAttachmentCount (count);
283287
284288 auto [result, framebuffer] =
285289 context.GetDevice ().createFramebufferUnique (fb_info);
0 commit comments