@@ -35,16 +35,6 @@ const char* layers[] = {
35
35
36
36
const uint32_t numLayers = 2 ;
37
37
38
- Controller::Controller ()
39
- {
40
- queuePriorities = new float [queueCount]();
41
- }
42
-
43
- Controller::~Controller ()
44
- {
45
- delete[] queuePriorities;
46
- }
47
-
48
38
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback (
49
39
VkDebugReportFlagsEXT flags,
50
40
VkDebugReportObjectTypeEXT objType,
@@ -60,7 +50,17 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
60
50
return VK_FALSE;
61
51
}
62
52
63
- bool Controller::Init ()
53
+ Controller::Controller ()
54
+ {
55
+ queuePriorities = new float [queueCount]();
56
+ }
57
+
58
+ Controller::~Controller ()
59
+ {
60
+ delete[] queuePriorities;
61
+ }
62
+
63
+ void Controller::Init ()
64
64
{
65
65
VkApplicationInfo appInfo = {};
66
66
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
@@ -115,6 +115,11 @@ bool Controller::Init()
115
115
break ;
116
116
}
117
117
}
118
+
119
+ if (supported == false )
120
+ {
121
+ throw std::runtime_error (" Extension not supported" );
122
+ }
118
123
119
124
createInfo.enabledExtensionCount = requestedExtensionCount;
120
125
createInfo.ppEnabledExtensionNames = requestedExtensions;
@@ -145,10 +150,14 @@ bool Controller::Init()
145
150
}
146
151
}
147
152
153
+ if (supported == false )
154
+ {
155
+ throw std::runtime_error (" Layer not supported" );
156
+ }
157
+
148
158
createInfo.enabledLayerCount = 1 ;
149
159
createInfo.ppEnabledLayerNames = layers;
150
160
151
-
152
161
VkResult result = vkCreateInstance (&createInfo, nullptr , &instance);
153
162
154
163
if (result != VK_SUCCESS)
@@ -167,7 +176,7 @@ bool Controller::Init()
167
176
168
177
if (callbackResult != VK_SUCCESS)
169
178
{
170
- std::cout << " error: did not create callback succesfuly" << std::endl ;
179
+ throw std::runtime_error ( " Callback not created succesfuly" ) ;
171
180
}
172
181
173
182
physicalDevice = VK_NULL_HANDLE;
@@ -176,7 +185,7 @@ bool Controller::Init()
176
185
177
186
if (deviceCount == 0 )
178
187
{
179
- std::cout << " failed to find a device that supports Vulkan" << std::endl ;
188
+ throw std::runtime_error ( " Failed to find a device that supports Vulkan" ) ;
180
189
}
181
190
182
191
VkPhysicalDevice* devices = new VkPhysicalDevice[deviceCount]();
@@ -205,7 +214,7 @@ bool Controller::Init()
205
214
206
215
if (foundDiscreteGPU == false )
207
216
{
208
- std::cout << " failed to find a discrete GPU" << std::endl ;
217
+ throw std::runtime_error ( " failed to find a discrete GPU" ) ;
209
218
}
210
219
211
220
vkGetPhysicalDeviceFeatures (physicalDevice, &deviceFeatures);
@@ -217,28 +226,24 @@ bool Controller::Init()
217
226
delete[] extensions;
218
227
219
228
CheckFormatPropertyType (VK_FORMAT_R32_SFLOAT, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
220
-
221
- return true ;
222
229
}
223
230
224
- bool Controller::Destroy ()
231
+ void Controller::Destroy ()
225
232
{
226
233
auto vkDestroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT) vkGetInstanceProcAddr (instance, " vkDestroyDebugReportCallbackEXT" );
227
234
vkDestroyDebugReportCallback (instance, callback, nullptr );
228
235
229
236
vkDestroyInstance (instance, nullptr );
230
-
231
- return true ;
232
237
}
233
238
234
- bool Controller::SetupQueue ()
239
+ void Controller::SetupQueue ()
235
240
{
236
241
uint32_t queueFamilyCount = 0 ;
237
242
vkGetPhysicalDeviceQueueFamilyProperties (physicalDevice, &queueFamilyCount, nullptr );
238
243
239
244
if (queueFamilyCount == 0 )
240
245
{
241
- std::cout << " failed to find a device that supports Vulkan " << std::endl ;
246
+ throw std::runtime_error ( " Failed to find a queue that supports the device " ) ;
242
247
}
243
248
244
249
VkQueueFamilyProperties* queueFamilies = new VkQueueFamilyProperties[queueFamilyCount]();
@@ -257,22 +262,20 @@ bool Controller::SetupQueue()
257
262
258
263
if (queueFamilyId == InvalidIndex)
259
264
{
260
- std::cout << " failed to get all indicies " << std::endl ;
265
+ throw std::runtime_error ( " Failed to get queue family index " ); ;
261
266
}
262
267
263
268
delete[] queueFamilies;
264
-
265
- return true ;
266
269
}
267
270
268
- bool Controller::SetupDevice (const VkSurfaceKHR& surface)
271
+ void Controller::SetupDevice (const VkSurfaceKHR& surface)
269
272
{
270
273
VkBool32 presentSupport = false ;
271
274
vkGetPhysicalDeviceSurfaceSupportKHR (physicalDevice, queueFamilyId, surface, &presentSupport);
272
275
273
276
if (presentSupport != true )
274
277
{
275
- std::cout << " surface presetation not supported" << std::endl ;
278
+ throw std::runtime_error ( " surface presetation not supported" ) ;
276
279
}
277
280
278
281
VkDeviceQueueCreateInfo queueCreateInfo = {};
@@ -309,7 +312,7 @@ bool Controller::SetupDevice(const VkSurfaceKHR& surface)
309
312
310
313
if (supported == false )
311
314
{
312
- std::cout << " VK_KHR_swapchain device extension not supported" << std::endl ;
315
+ throw std::runtime_error ( " VK_KHR_swapchain device extension not supported" ) ;
313
316
}
314
317
315
318
VkDeviceCreateInfo deviceCreateInfo = {};
@@ -326,15 +329,13 @@ bool Controller::SetupDevice(const VkSurfaceKHR& surface)
326
329
327
330
if (deviceResult != VK_SUCCESS)
328
331
{
329
- std::cout << " failed to create device" << std::endl ;
332
+ throw std::runtime_error ( " failed to create device" ) ;
330
333
}
331
334
332
335
delete[] availableDeviceExtensions;
333
-
334
- return true ;
335
336
}
336
337
337
- bool Controller::Configure (const VkSurfaceKHR& surface)
338
+ void Controller::Configure (const VkSurfaceKHR& surface)
338
339
{
339
340
vkGetPhysicalDeviceSurfaceCapabilitiesKHR (physicalDevice, surface, &capabilities);
340
341
@@ -344,10 +345,8 @@ bool Controller::Configure(const VkSurfaceKHR& surface)
344
345
345
346
if ((capabilities.supportedTransforms & transform) == 0 )
346
347
{
347
- std::cout << " Transform not supported" << std::endl ;
348
+ throw std::runtime_error ( " Transform not supported" ) ;
348
349
}
349
-
350
- return true ;
351
350
}
352
351
353
352
void Controller::PrintCapabilities () const
@@ -437,21 +436,15 @@ bool Controller::SurfaceFormatSupported(const VkSurfaceKHR& surface, VkFormat su
437
436
return supported;
438
437
}
439
438
440
- bool Controller::CheckFormatPropertyType (VkFormat format, VkFormatFeatureFlagBits flags) const
439
+ void Controller::CheckFormatPropertyType (VkFormat format, VkFormatFeatureFlagBits flags) const
441
440
{
442
441
VkFormatProperties formatProps;
443
442
vkGetPhysicalDeviceFormatProperties (physicalDevice, format, &formatProps);
444
443
445
- if (formatProps.optimalTilingFeatures & flags)
446
- {
447
- return true ;
448
- }
449
- else
444
+ if ((formatProps.optimalTilingFeatures & flags) == 0 )
450
445
{
451
446
throw std::runtime_error (" Format property not optimal" );
452
447
}
453
-
454
- return false ;
455
448
}
456
449
457
450
};
0 commit comments