@@ -240,15 +240,18 @@ bool Anvil::GraphicsPipelineManager::bake()
240240 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info;
241241 VkLogicOp logic_op;
242242 bool logic_op_enabled = false ;
243+ uint32_t max_location_index = UINT32_MAX;
243244 const uint32_t start_offset = static_cast <uint32_t >(color_blend_attachment_states_vk_cache.size () );
244245
246+ max_location_index = current_pipeline_renderpass_ptr->get_render_pass_create_info ()->get_max_color_location_used_by_subpass (current_pipeline_subpass_id);
247+
245248 current_pipeline_create_info_ptr->get_blending_properties (&blend_constant_ptr,
246249 nullptr ); /* out_opt_n_blend_attachments_ptr */
247250
248251 current_pipeline_create_info_ptr->get_logic_op_state (&logic_op_enabled,
249252 &logic_op);
250253
251- color_blend_state_create_info.attachmentCount = subpass_n_color_attachments ;
254+ color_blend_state_create_info.attachmentCount = max_location_index + 1 ;
252255 color_blend_state_create_info.flags = 0 ;
253256 color_blend_state_create_info.logicOp = logic_op;
254257 color_blend_state_create_info.logicOpEnable = (logic_op_enabled) ? VK_TRUE : VK_FALSE;
@@ -260,24 +263,33 @@ bool Anvil::GraphicsPipelineManager::bake()
260263 blend_constant_ptr,
261264 sizeof (color_blend_state_create_info.blendConstants ) );
262265
266+ anvil_assert (subpass_n_color_attachments <= current_pipeline_renderpass_ptr->get_render_pass_create_info ()->get_n_attachments () );
267+
263268 for (uint32_t n_subpass_color_attachment = 0 ;
264- n_subpass_color_attachment < subpass_n_color_attachments ;
269+ n_subpass_color_attachment <= max_location_index ;
265270 ++n_subpass_color_attachment)
266271 {
267272 color_blend_attachment_states_vk_cache.push_back (VkPipelineColorBlendAttachmentState () );
268273
269274 VkPipelineColorBlendAttachmentState* blend_attachment_state_ptr = &color_blend_attachment_states_vk_cache.back ();
275+ VkImageLayout dummy = VK_IMAGE_LAYOUT_MAX_ENUM;
270276 bool is_blending_enabled_for_attachment = false ;
271-
272- if (!current_pipeline_create_info_ptr->get_color_blend_attachment_properties (n_subpass_color_attachment,
273- &is_blending_enabled_for_attachment,
274- &blend_attachment_state_ptr->colorBlendOp ,
275- &blend_attachment_state_ptr->alphaBlendOp ,
276- &blend_attachment_state_ptr->srcColorBlendFactor ,
277- &blend_attachment_state_ptr->dstColorBlendFactor ,
278- &blend_attachment_state_ptr->srcAlphaBlendFactor ,
279- &blend_attachment_state_ptr->dstAlphaBlendFactor ,
280- &blend_attachment_state_ptr->colorWriteMask ) )
277+ Anvil::RenderPassAttachmentID rp_attachment_id = UINT32_MAX;
278+
279+ if (!current_pipeline_renderpass_ptr->get_render_pass_create_info ()->get_subpass_attachment_properties (current_pipeline_subpass_id,
280+ Anvil::ATTACHMENT_TYPE_COLOR,
281+ n_subpass_color_attachment,
282+ &rp_attachment_id,
283+ &dummy) || /* out_layout_ptr */
284+ !current_pipeline_create_info_ptr->get_color_blend_attachment_properties (rp_attachment_id,
285+ &is_blending_enabled_for_attachment,
286+ &blend_attachment_state_ptr->colorBlendOp ,
287+ &blend_attachment_state_ptr->alphaBlendOp ,
288+ &blend_attachment_state_ptr->srcColorBlendFactor ,
289+ &blend_attachment_state_ptr->dstColorBlendFactor ,
290+ &blend_attachment_state_ptr->srcAlphaBlendFactor ,
291+ &blend_attachment_state_ptr->dstAlphaBlendFactor ,
292+ &blend_attachment_state_ptr->colorWriteMask ) )
281293 {
282294 /* The user has not defined blending properties for current color attachment. Use default state values .. */
283295 blend_attachment_state_ptr->blendEnable = VK_FALSE;
@@ -294,9 +306,7 @@ bool Anvil::GraphicsPipelineManager::bake()
294306 }
295307 else
296308 {
297- anvil_assert (is_blending_enabled_for_attachment);
298-
299- blend_attachment_state_ptr->blendEnable = VK_TRUE;
309+ blend_attachment_state_ptr->blendEnable = (is_blending_enabled_for_attachment) ? VK_TRUE : VK_FALSE;
300310 }
301311 }
302312
0 commit comments