@@ -66,15 +66,21 @@ pub fn create_pipeline_with_defaults(
6666
6767 let dynamic_state = ps_dynamic_state ( & [ vk:: DynamicState :: VIEWPORT , vk:: DynamicState :: SCISSOR ] ) ;
6868
69+ let mut attachment_blends =
70+ Vec :: < vk:: PipelineColorBlendAttachmentState > :: with_capacity ( color_attachment_count) ;
71+
6972 // create pipeline itself
7073 let stages = [ stage_vs, stage_fs] ;
7174 let input_assembly_state = ps_ia_triangle_list ( ) ;
7275 let viewport_state = ps_viewport_single_dynamic ( ) ;
7376 let rasterization_state = ps_raster_polygons ( vk:: CullModeFlags :: NONE ) ;
7477 let multisample_state = ps_multisample_disabled ( ) ;
7578 let depth_stencil_state = ps_depth_always_stencil_always ( ) ;
76- let color_blend_state =
77- ps_color_blend_override ( color_attachment_count, vk:: ColorComponentFlags :: RGBA ) ;
79+ let color_blend_state = ps_color_blend_override (
80+ & mut attachment_blends,
81+ color_attachment_count,
82+ vk:: ColorComponentFlags :: RGBA ,
83+ ) ;
7884 let create_info_builder = vk:: GraphicsPipelineCreateInfo :: builder ( )
7985 . stages ( & stages)
8086 . vertex_input_state ( & vertex_desc)
@@ -267,44 +273,48 @@ pub fn ps_multisample_disabled() -> vk::PipelineMultisampleStateCreateInfo {
267273}
268274
269275/// Write result to all color attachments, disable blending
270- fn ps_color_attachments_write_all (
271- attachment_count : usize ,
276+ pub fn ps_color_attachment_override (
272277 color_write_mask : vk:: ColorComponentFlags ,
273- ) -> Vec < vk:: PipelineColorBlendAttachmentState > {
274- // VULKAN SPEC:
275- // > If the independent blending feature is not enabled on the device,
276- // all VkPipelineColorBlendAttachmentState elements in the pAttachments
277- // array must be identical.
278-
278+ ) -> vk:: PipelineColorBlendAttachmentState {
279279 // PS. I always hated blend state
280- let write_all = vk:: PipelineColorBlendAttachmentState :: builder ( )
280+ vk:: PipelineColorBlendAttachmentState :: builder ( )
281281 . color_write_mask ( color_write_mask)
282282 . blend_enable ( false )
283283 . src_color_blend_factor ( vk:: BlendFactor :: ONE ) // shader output
284284 . dst_color_blend_factor ( vk:: BlendFactor :: ZERO ) // existing value on destination attachment
285285 . src_alpha_blend_factor ( vk:: BlendFactor :: ONE ) // shader output
286286 . dst_alpha_blend_factor ( vk:: BlendFactor :: ZERO ) // existing value on destination attachment
287- . build ( ) ;
287+ . build ( )
288+ }
288289
289- let mut attachments =
290- Vec :: < vk:: PipelineColorBlendAttachmentState > :: with_capacity ( attachment_count) ;
291- for _i in 0 ..attachment_count {
292- attachments. push ( write_all) ;
290+ /// Copy blends state `color_attachment_count` times.
291+ ///
292+ /// **VULKAN SPEC:**
293+ /// > If the independent blending feature is not enabled on the device,
294+ /// all VkPipelineColorBlendAttachmentState elements in the pAttachments
295+ /// array must be identical.
296+ pub fn ps_color_blend_state (
297+ attachment_blends : & mut Vec < vk:: PipelineColorBlendAttachmentState > , // needed cause `PipelineColorBlendAttachmentState` has ref
298+ color_attachment_count : usize ,
299+ blend_state : vk:: PipelineColorBlendAttachmentState ,
300+ ) -> vk:: PipelineColorBlendStateCreateInfo {
301+ for _i in 0 ..color_attachment_count {
302+ attachment_blends. push ( blend_state) ;
293303 }
294304
295- attachments
305+ vk:: PipelineColorBlendStateCreateInfo :: builder ( )
306+ . attachments ( & attachment_blends)
307+ . build ( )
296308}
297309
298310/// Write result to all color attachments, disable blending
299311pub fn ps_color_blend_override (
312+ attachment_blends : & mut Vec < vk:: PipelineColorBlendAttachmentState > ,
300313 color_attachment_count : usize ,
301314 color_write_mask : vk:: ColorComponentFlags ,
302315) -> vk:: PipelineColorBlendStateCreateInfo {
303- let color_attachments_write_all =
304- ps_color_attachments_write_all ( color_attachment_count, color_write_mask) ;
305- vk:: PipelineColorBlendStateCreateInfo :: builder ( )
306- . attachments ( & color_attachments_write_all)
307- . build ( )
316+ let blend_state = ps_color_attachment_override ( color_write_mask) ;
317+ ps_color_blend_state ( attachment_blends, color_attachment_count, blend_state)
308318}
309319
310320/// List of things that will be provided as separate command before draw (actuall 'runtime').
0 commit comments