1 private@ 2 3 type Version = struct 4 vertex_format : VertexFormat 5 render_pass : RenderPass 6 pipeline : Pipeline 7 8 public@ 9 10 type PipelineCache = 11 val instance : Instance @auto 12 val vertex_shader : VertexShader 13 val fragment_shader : FragmentShader 14 val rasterization : Rasterization 15 val multisample : Multisample 16 val depth_stencil : DepthStencil 17 val color_blend : ColorBlend 18 val pipeline_layout : PipelineLayout 19 let versions = List<Version>.new 20 21 let create (vertex_format : VertexFormat) (render_pass : RenderPass) = 22 let color_attachment_count = render_pass.format.attachments 23 |> count { _.usage.contains ImageUsageFlags/ColorAttachment } 24 25 let blend = 26 if color_attachment_count > 0 27 && color_blend.attachments.is_empty 28 then ColorBlend.create color_attachment_count.as<i32> 29 else color_blend 30 31 Pipeline.create vertex_shader fragment_shader pipeline_layout 32 render_pass vertex_format rasterization 33 multisample = Multisample 34 samples = render_pass.samples 35 f@ multisample 36 37 =depth_stencil 38 =blend 39 subpass = 0 40 41 def get (vertex_format : VertexFormat) (render_pass : RenderPass) = 42 for version in versions do 43 if version.vertex_format == vertex_format 44 && version.render_pass == render_pass 45 then 46 return version.pipeline 47 48 let pipeline = create vertex_format render_pass 49 versions.add (Version vertex_format render_pass pipeline) 50 51 pipeline 52