-
Notifications
You must be signed in to change notification settings - Fork 2
/
11_render_passes.diff
89 lines (83 loc) · 2.41 KB
/
11_render_passes.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
diff --git a/../steps/10_fixed_functions/main.go b/../steps/11_render_passes/main.go
index 76e61c8..81b6945 100644
--- a/../steps/10_fixed_functions/main.go
+++ b/../steps/11_render_passes/main.go
@@ -60,6 +60,7 @@ type HelloTriangleApplication struct {
swapchainExtent core1_0.Extent2D
swapchainImageViews []core1_0.ImageView
+ renderPass core1_0.RenderPass
pipelineLayout core1_0.PipelineLayout
}
@@ -128,6 +129,11 @@ func (app *HelloTriangleApplication) initVulkan() error {
return err
}
+ err = app.createRenderPass()
+ if err != nil {
+ return err
+ }
+
return app.createGraphicsPipeline()
}
@@ -150,6 +156,10 @@ func (app *HelloTriangleApplication) cleanup() {
app.pipelineLayout.Destroy(nil)
}
+ if app.renderPass != nil {
+ app.renderPass.Destroy(nil)
+ }
+
for _, imageView := range app.swapchainImageViews {
imageView.Destroy(nil)
}
@@ -436,6 +446,53 @@ func (app *HelloTriangleApplication) createSwapchain() error {
return nil
}
+func (app *HelloTriangleApplication) createRenderPass() error {
+ renderPass, _, err := app.device.CreateRenderPass(nil, core1_0.RenderPassCreateInfo{
+ Attachments: []core1_0.AttachmentDescription{
+ {
+ Format: app.swapchainImageFormat,
+ Samples: core1_0.Samples1,
+ LoadOp: core1_0.AttachmentLoadOpClear,
+ StoreOp: core1_0.AttachmentStoreOpStore,
+ StencilLoadOp: core1_0.AttachmentLoadOpDontCare,
+ StencilStoreOp: core1_0.AttachmentStoreOpDontCare,
+ InitialLayout: core1_0.ImageLayoutUndefined,
+ FinalLayout: khr_swapchain.ImageLayoutPresentSrc,
+ },
+ },
+ Subpasses: []core1_0.SubpassDescription{
+ {
+ PipelineBindPoint: core1_0.PipelineBindPointGraphics,
+ ColorAttachments: []core1_0.AttachmentReference{
+ {
+ Attachment: 0,
+ Layout: core1_0.ImageLayoutColorAttachmentOptimal,
+ },
+ },
+ },
+ },
+ SubpassDependencies: []core1_0.SubpassDependency{
+ {
+ SrcSubpass: core1_0.SubpassExternal,
+ DstSubpass: 0,
+
+ SrcStageMask: core1_0.PipelineStageColorAttachmentOutput,
+ SrcAccessMask: 0,
+
+ DstStageMask: core1_0.PipelineStageColorAttachmentOutput,
+ DstAccessMask: core1_0.AccessColorAttachmentWrite,
+ },
+ },
+ })
+ if err != nil {
+ return err
+ }
+
+ app.renderPass = renderPass
+
+ return nil
+}
+
func bytesToBytecode(b []byte) []uint32 {
byteCode := make([]uint32, len(b)/4)
for i := 0; i < len(byteCode); i++ {