Mercurial > games > semicongine
annotate semiconginev2/rendering/renderpasses.nim @ 1237:97813ac43cfb
add: multi-text with all properties animated
author | sam <sam@basx.dev> |
---|---|
date | Sun, 21 Jul 2024 00:03:48 +0700 |
parents | 5dcb503ef0c0 |
children |
rev | line source |
---|---|
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
1 proc CreateDirectPresentationRenderPass*(depthBuffer: bool, samples = VK_SAMPLE_COUNT_1_BIT): RenderPass = |
1204 | 2 assert vulkan.instance.Valid, "Vulkan not initialized" |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
3 result = RenderPass(depthBuffer: depthBuffer, samples: samples) |
1204 | 4 |
1199 | 5 var attachments = @[VkAttachmentDescription( |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
6 format: SURFACE_FORMAT, |
1199 | 7 samples: samples, |
8 loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, | |
9 storeOp: VK_ATTACHMENT_STORE_OP_STORE, | |
10 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, | |
11 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, | |
12 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, | |
13 finalLayout: if samples == VK_SAMPLE_COUNT_1_BIT: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR else: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, | |
14 )] | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
15 if depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
16 attachments.add VkAttachmentDescription( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
17 format: DEPTH_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
18 samples: samples, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
19 loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
20 storeOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
21 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
22 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
23 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
24 finalLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
25 ) |
1199 | 26 if samples != VK_SAMPLE_COUNT_1_BIT: |
27 attachments.add VkAttachmentDescription( | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
28 format: SURFACE_FORMAT, |
1199 | 29 samples: VK_SAMPLE_COUNT_1_BIT, |
30 loadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, | |
31 storeOp: VK_ATTACHMENT_STORE_OP_STORE, | |
32 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, | |
33 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, | |
34 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, | |
35 finalLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, | |
36 ) | |
37 var | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
38 dependencies = @[ |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
39 VkSubpassDependency( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
40 srcSubpass: VK_SUBPASS_EXTERNAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
41 dstSubpass: 0, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
42 srcStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
43 dstStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT], |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
44 srcAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
45 dstAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT], |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
46 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
47 ] |
1199 | 48 colorAttachment = VkAttachmentReference( |
49 attachment: 0, | |
50 layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, | |
51 ) | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
52 depthAttachment = VkAttachmentReference( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
53 attachment: 1, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
54 layout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
55 ) |
1199 | 56 resolveAttachment = VkAttachmentReference( |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
57 attachment: (attachments.len - 1).uint32, # depending on whether depthBuffer is used or not |
1199 | 58 layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
59 ) | |
60 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
61 result.vk = svkCreateRenderPass( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
62 attachments = attachments, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
63 colorAttachments = [colorAttachment], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
64 depthAttachments = if depthBuffer: @[depthAttachment] else: @[], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
65 resolveAttachments = if samples > VK_SAMPLE_COUNT_1_BIT: @[resolveAttachment] else: @[], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
66 dependencies = dependencies, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
67 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
68 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
69 proc CreateIndirectPresentationRenderPass*(depthBuffer: bool, samples = VK_SAMPLE_COUNT_1_BIT): (RenderPass, RenderPass) = |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
70 assert vulkan.instance.Valid, "Vulkan not initialized" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
71 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
72 result[0] = RenderPass(depthBuffer: depthBuffer, samples: samples) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
73 result[1] = RenderPass(depthBuffer: false, samples: VK_SAMPLE_COUNT_1_BIT) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
74 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
75 # first renderpass, drawing |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
76 var |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
77 attachments = @[VkAttachmentDescription( |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
78 format: SURFACE_FORMAT, # not strictly necessary |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
79 samples: samples, |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
80 loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
81 storeOp: VK_ATTACHMENT_STORE_OP_STORE, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
82 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
83 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
84 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
85 # finalLayout: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
86 finalLayout: if samples == VK_SAMPLE_COUNT_1_BIT: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL else: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
87 )] |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
88 if depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
89 attachments.add VkAttachmentDescription( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
90 format: DEPTH_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
91 samples: samples, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
92 loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
93 storeOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
94 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
95 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
96 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
97 finalLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
98 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
99 if samples != VK_SAMPLE_COUNT_1_BIT: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
100 attachments.add VkAttachmentDescription( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
101 format: SURFACE_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
102 samples: VK_SAMPLE_COUNT_1_BIT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
103 loadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
104 storeOp: VK_ATTACHMENT_STORE_OP_STORE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
105 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
106 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
107 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
108 finalLayout: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
109 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
110 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
111 var |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
112 dependencies = @[ |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
113 VkSubpassDependency( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
114 srcSubpass: VK_SUBPASS_EXTERNAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
115 dstSubpass: 0, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
116 srcStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
117 dstStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
118 srcAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
119 dstAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT], |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
120 ), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
121 VkSubpassDependency( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
122 srcSubpass: VK_SUBPASS_EXTERNAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
123 dstSubpass: 0, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
124 srcStageMask: toBits [VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
125 dstStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
126 srcAccessMask: toBits [VK_ACCESS_SHADER_READ_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
127 dstAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
128 ), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
129 VkSubpassDependency( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
130 srcSubpass: 0, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
131 dstSubpass: VK_SUBPASS_EXTERNAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
132 srcStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
133 dstStageMask: toBits [VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
134 srcAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
135 dstAccessMask: toBits [VK_ACCESS_SHADER_READ_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
136 ), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
137 ] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
138 colorAttachment = VkAttachmentReference( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
139 attachment: 0, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
140 layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
141 ) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
142 depthAttachment = VkAttachmentReference( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
143 attachment: 1, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
144 layout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
145 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
146 resolveAttachment = VkAttachmentReference( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
147 attachment: (attachments.len - 1).uint32, # depending on whether depthBuffer is used or not |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
148 layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
149 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
150 result[0].vk = svkCreateRenderPass( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
151 attachments = attachments, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
152 colorAttachments = [colorAttachment], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
153 depthAttachments = if depthBuffer: @[depthAttachment] else: @[], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
154 resolveAttachments = if samples > VK_SAMPLE_COUNT_1_BIT: @[resolveAttachment] else: @[], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
155 dependencies = dependencies |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
156 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
157 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
158 # second renderpass, presentation |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
159 var |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
160 presentAttachments = @[VkAttachmentDescription( |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
161 format: SURFACE_FORMAT, |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
162 samples: VK_SAMPLE_COUNT_1_BIT, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
163 loadOp: VK_ATTACHMENT_LOAD_OP_CLEAR, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
164 storeOp: VK_ATTACHMENT_STORE_OP_STORE, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
165 stencilLoadOp: VK_ATTACHMENT_LOAD_OP_DONT_CARE, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
166 stencilStoreOp: VK_ATTACHMENT_STORE_OP_DONT_CARE, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
167 initialLayout: VK_IMAGE_LAYOUT_UNDEFINED, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
168 finalLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
169 )] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
170 presentDependencies = @[VkSubpassDependency( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
171 srcSubpass: VK_SUBPASS_EXTERNAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
172 dstSubpass: 0, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
173 srcStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
174 dstStageMask: toBits [VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
175 srcAccessMask: VkAccessFlags(0), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
176 dstAccessMask: toBits [VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT], |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
177 )] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
178 presentColorAttachment = VkAttachmentReference( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
179 attachment: 0, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
180 layout: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
181 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
182 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
183 result[1].vk = svkCreateRenderPass( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
184 attachments = presentAttachments, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
185 colorAttachments = [presentColorAttachment], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
186 depthAttachments = [], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
187 resolveAttachments = [], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
188 dependencies = presentDependencies |
1199 | 189 ) |
190 | |
191 template WithRenderPass*( | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
192 theRenderpass: RenderPass, |
1199 | 193 theFramebuffer: VkFramebuffer, |
194 commandbuffer: VkCommandBuffer, | |
195 renderWidth: uint32, | |
196 renderHeight: uint32, | |
197 clearColor: Vec4f, | |
198 body: untyped | |
199 ): untyped = | |
200 var | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
201 clearColors = [ |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
202 VkClearValue(color: VkClearColorValue(float32: clearColor)), |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
203 VkClearValue(depthStencil: VkClearDepthStencilValue(depth: 1'f32, stencil: 0)) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
204 ] |
1199 | 205 renderPassInfo = VkRenderPassBeginInfo( |
206 sType: VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
207 renderPass: theRenderpass.vk, |
1199 | 208 framebuffer: theFramebuffer, |
209 renderArea: VkRect2D( | |
210 offset: VkOffset2D(x: 0, y: 0), | |
211 extent: VkExtent2D(width: renderWidth, height: renderHeight), | |
212 ), | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1218
diff
changeset
|
213 clearValueCount: clearColors.len.uint32, |
1199 | 214 pClearValues: clearColors.ToCPointer(), |
215 ) | |
216 viewport = VkViewport( | |
217 x: 0.0, | |
1204 | 218 y: renderHeight.float32, |
1199 | 219 width: renderWidth.float32, |
1204 | 220 height: -renderHeight.float32, |
1199 | 221 minDepth: 0.0, |
222 maxDepth: 1.0, | |
223 ) | |
224 scissor = VkRect2D( | |
225 offset: VkOffset2D(x: 0, y: 0), | |
226 extent: VkExtent2D(width: renderWidth, height: renderHeight) | |
227 ) | |
228 | |
229 vkCmdBeginRenderPass(commandbuffer, addr(renderPassInfo), VK_SUBPASS_CONTENTS_INLINE) | |
230 | |
231 # setup viewport | |
232 vkCmdSetViewport(commandbuffer, firstViewport = 0, viewportCount = 1, addr(viewport)) | |
233 vkCmdSetScissor(commandbuffer, firstScissor = 0, scissorCount = 1, addr(scissor)) | |
234 | |
235 block: | |
236 body | |
237 | |
238 vkCmdEndRenderPass(commandbuffer) |