forked from vkngwrapper/vulkan-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_window_surface.diff
124 lines (108 loc) · 3.49 KB
/
05_window_surface.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
diff --git a/../steps/04_logical_device/main.go b/../steps/05_window_surface/main.go
index 7a70772..35cb968 100644
--- a/../steps/04_logical_device/main.go
+++ b/../steps/05_window_surface/main.go
@@ -3,12 +3,14 @@ package main
import (
"github.com/cockroachdb/errors"
"github.com/veandco/go-sdl2/sdl"
+ "github.com/vkngwrapper/core/v2"
"github.com/vkngwrapper/core/v2/common"
"github.com/vkngwrapper/core/v2/core1_0"
- "github.com/vkngwrapper/core/v2"
"github.com/vkngwrapper/extensions/v2/ext_debug_utils"
"github.com/vkngwrapper/extensions/v2/khr_portability_enumeration"
"github.com/vkngwrapper/extensions/v2/khr_portability_subset"
+ "github.com/vkngwrapper/extensions/v2/khr_surface"
+ vkng_sdl2 "github.com/vkngwrapper/integrations/sdl2/v2"
"log"
)
@@ -18,10 +20,11 @@ const enableValidationLayers = true
type QueueFamilyIndices struct {
GraphicsFamily *int
+ PresentFamily *int
}
func (i *QueueFamilyIndices) IsComplete() bool {
- return i.GraphicsFamily != nil
+ return i.GraphicsFamily != nil && i.PresentFamily != nil
}
type HelloTriangleApplication struct {
@@ -30,11 +33,13 @@ type HelloTriangleApplication struct {
instance core1_0.Instance
debugMessenger ext_debug_utils.DebugUtilsMessenger
+ surface khr_surface.Surface
physicalDevice core1_0.PhysicalDevice
device core1_0.Device
graphicsQueue core1_0.Queue
+ presentQueue core1_0.Queue
}
func (app *HelloTriangleApplication) Run() error {
@@ -82,6 +87,11 @@ func (app *HelloTriangleApplication) initVulkan() error {
return err
}
+ err = app.createSurface()
+ if err != nil {
+ return err
+ }
+
err = app.pickPhysicalDevice()
if err != nil {
return err
@@ -113,6 +123,10 @@ func (app *HelloTriangleApplication) cleanup() {
app.debugMessenger.Destroy(nil)
}
+ if app.surface != nil {
+ app.surface.Destroy(nil)
+ }
+
if app.instance != nil {
app.instance.Destroy(nil)
}
@@ -207,6 +221,18 @@ func (app *HelloTriangleApplication) setupDebugMessenger() error {
return nil
}
+func (app *HelloTriangleApplication) createSurface() error {
+ surfaceLoader := khr_surface.CreateExtensionFromInstance(app.instance)
+
+ surface, err := vkng_sdl2.CreateSurface(app.instance, surfaceLoader, app.window)
+ if err != nil {
+ return err
+ }
+
+ app.surface = surface
+ return nil
+}
+
func (app *HelloTriangleApplication) pickPhysicalDevice() error {
physicalDevices, _, err := app.instance.EnumeratePhysicalDevices()
if err != nil {
@@ -234,6 +260,9 @@ func (app *HelloTriangleApplication) createLogicalDevice() error {
}
uniqueQueueFamilies := []int{*indices.GraphicsFamily}
+ if uniqueQueueFamilies[0] != *indices.PresentFamily {
+ uniqueQueueFamilies = append(uniqueQueueFamilies, *indices.PresentFamily)
+ }
var queueFamilyOptions []core1_0.DeviceQueueCreateInfo
queuePriority := float32(1.0)
@@ -267,6 +296,7 @@ func (app *HelloTriangleApplication) createLogicalDevice() error {
}
app.graphicsQueue = app.device.GetQueue(*indices.GraphicsFamily, 0)
+ app.presentQueue = app.device.GetQueue(*indices.PresentFamily, 0)
return nil
}
@@ -289,6 +319,16 @@ func (app *HelloTriangleApplication) findQueueFamilies(device core1_0.PhysicalDe
*indices.GraphicsFamily = queueFamilyIdx
}
+ supported, _, err := app.surface.PhysicalDeviceSurfaceSupport(device, queueFamilyIdx)
+ if err != nil {
+ return indices, err
+ }
+
+ if supported {
+ indices.PresentFamily = new(int)
+ *indices.PresentFamily = queueFamilyIdx
+ }
+
if indices.IsComplete() {
break
}