1    object Vulkan =
2        val subpass_external : u32 = 0xFFFFFFFF
3        val attachment_unused : i32 = -1
4    
5    type AttachmentFormat @data =
6        val format : VkFormat
7        val samples : SampleCountFlags
8        val usage : ImageUsageFlags
9    
10   type SubpassFormat @data =
11       val color_attachments : List<i32>
12       val input_attachments : List<i32>
13       val resolve_attachments : List<i32>
14       val preserve_attachments : List<i32>
15       val depth_attachment : i32
16   
17   type RenderPassFormat @data =
18       val attachments : List<AttachmentFormat>
19       val subpasses : List<SubpassFormat>
20   
21   object AttachmentFormat =
22       val default = AttachmentFormat
23           format = VkFormat/R8G8B8A8_UNORM
24           samples = SampleCountFlags/1
25           usage = ImageUsageFlags@zero
26   
27   object RenderPassFormat =
28       def create (attachments : List<AttachmentFormat>) =
29           let (depth_attachments, color_attachments) = attachments
30               |> with_index
31               |> partition { _, x ->
32                   x.usage.contains ImageUsageFlags/DepthStencilAttachment }
33   
34           let depth_attachment = depth_attachments
35               |> map { i, _ -> i as i32 }
36               |> try_single
37               |> unwrap_or Vulkan.attachment_unused
38   
39           let subpass = SubpassFormat
40               color_attachments = color_attachments.map { i, _ -> i as i32 }
41               input_attachments = List<i32>.empty
42               resolve_attachments = List<i32>.empty
43               preserve_attachments = List<i32>.empty
44               =depth_attachment
45   
46           let format = RenderPassFormat
47               =attachments
48               subpasses = [subpass]
49   
50           format
51