Skip to content

Commit eac38d0

Browse files
committed
More cleanup
Removed redundnant bool return statements
1 parent 730c58f commit eac38d0

10 files changed

+74
-117
lines changed

commands.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void Commands::SetupImage(VkDevice& device, VkImage& image, const VkExtent3D& ex
7979
}
8080
}
8181

82-
bool Commands::SetupBuffer(VkDevice& device, VkBuffer& buffer, VkDeviceMemory& memory, VkDeviceSize size, VkMemoryPropertyFlags properties, VkBufferUsageFlags usage)
82+
void Commands::SetupBuffer(VkDevice& device, VkBuffer& buffer, VkDeviceMemory& memory, VkDeviceSize size, VkMemoryPropertyFlags properties, VkBufferUsageFlags usage)
8383
{
8484
VkBufferCreateInfo bufferInfo = {};
8585
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@@ -114,8 +114,6 @@ bool Commands::SetupBuffer(VkDevice& device, VkBuffer& buffer, VkDeviceMemory& m
114114
}
115115

116116
vkBindBufferMemory(device, buffer, memory, 0);
117-
118-
return true;
119117
}
120118

121119
uint32_t Commands::GetMemoryTypeIndex(VkDevice& device, const VkMemoryRequirements& memRequirements, const VkPhysicalDeviceMemoryProperties& props, VkMemoryPropertyFlags propFlags, uint32_t& allocSize) const

commands.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Commands
3737

3838
protected:
3939
void SetupImage(VkDevice& device, VkImage& image, const VkExtent3D& extent, const VkFormat& format, VkDeviceMemory& memory, VkMemoryPropertyFlags properties, VkBufferUsageFlags usage);
40-
bool SetupBuffer(VkDevice& device, VkBuffer& buffer, VkDeviceMemory& memory, VkDeviceSize size, VkMemoryPropertyFlags properties, VkBufferUsageFlags usage);
40+
void SetupBuffer(VkDevice& device, VkBuffer& buffer, VkDeviceMemory& memory, VkDeviceSize size, VkMemoryPropertyFlags properties, VkBufferUsageFlags usage);
4141
uint32_t GetMemoryTypeIndex(VkDevice& device, const VkMemoryRequirements& memReqs, const VkPhysicalDeviceMemoryProperties& props, VkMemoryPropertyFlags propFlags, uint32_t& allocSize) const;
4242

4343
const VkPhysicalDeviceMemoryProperties& memProperties;

compositor.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Compositor::~Compositor()
4040
delete[] imageViews;
4141
}
4242

43-
bool Compositor::Init(VkDevice& device,
43+
void Compositor::Init(VkDevice& device,
4444
const VkSurfaceKHR& surface,
4545
uint32_t width,
4646
uint32_t height,
@@ -150,11 +150,9 @@ bool Compositor::Init(VkDevice& device,
150150

151151
vkCreateSemaphore(device, &semaphoreInfo, nullptr, &waitSemaphore);
152152
vkCreateSemaphore(device, &semaphoreInfo, nullptr, &signalSemaphore);
153-
154-
return true;
155153
}
156154

157-
bool Compositor::Destroy(VkDevice& device)
155+
void Compositor::Destroy(VkDevice& device)
158156
{
159157
vkDestroySemaphore(device, waitSemaphore, nullptr);
160158
vkDestroySemaphore(device, signalSemaphore, nullptr);
@@ -174,13 +172,11 @@ bool Compositor::Destroy(VkDevice& device)
174172

175173
vkDestroySwapchainKHR(device, swapChain, nullptr);
176174
vkDestroyDevice(device, nullptr);
177-
178-
return true;
179175
}
180176

181177
//bool once = true;
182178

183-
bool Compositor::Draw(VkDevice& device)
179+
void Compositor::Draw(VkDevice& device)
184180
{
185181
computer->UpdateWave(device);
186182

@@ -248,8 +244,6 @@ bool Compositor::Draw(VkDevice& device)
248244

249245
// Increment draw index to use correct image view for next frame
250246
drawIndex = (drawIndex + 1) % 2;
251-
252-
return true;
253247
}
254248

255249
};

compositor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Compositor
3838
Compositor& operator=(const Compositor&) = delete;
3939
Compositor& operator=(Compositor &&) = delete;
4040

41-
bool Init(VkDevice& device,
41+
void Init(VkDevice& device,
4242
const VkSurfaceKHR& surface,
4343
uint32_t width,
4444
uint32_t height,
@@ -48,12 +48,12 @@ class Compositor
4848
uint32_t computeQueueIndex);
4949

5050
void Loop();
51-
bool Destroy(VkDevice& device);
51+
void Destroy(VkDevice& device);
5252

5353
inline VkFormat GetSurfaceFormat() const { return surfaceFormat; }
5454
inline VkPresentModeKHR GetPresentMode() const { return presentMode; }
5555

56-
bool Draw(VkDevice& device);
56+
void Draw(VkDevice& device);
5757

5858
private:
5959
void PrintCapabilities();

controller.cpp

+36-43
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ const char* layers[] = {
3535

3636
const uint32_t numLayers = 2;
3737

38-
Controller::Controller()
39-
{
40-
queuePriorities = new float[queueCount]();
41-
}
42-
43-
Controller::~Controller()
44-
{
45-
delete[] queuePriorities;
46-
}
47-
4838
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
4939
VkDebugReportFlagsEXT flags,
5040
VkDebugReportObjectTypeEXT objType,
@@ -60,7 +50,17 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
6050
return VK_FALSE;
6151
}
6252

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()
6464
{
6565
VkApplicationInfo appInfo = {};
6666
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
@@ -115,6 +115,11 @@ bool Controller::Init()
115115
break;
116116
}
117117
}
118+
119+
if (supported == false)
120+
{
121+
throw std::runtime_error("Extension not supported");
122+
}
118123

119124
createInfo.enabledExtensionCount = requestedExtensionCount;
120125
createInfo.ppEnabledExtensionNames = requestedExtensions;
@@ -145,10 +150,14 @@ bool Controller::Init()
145150
}
146151
}
147152

153+
if (supported == false)
154+
{
155+
throw std::runtime_error("Layer not supported");
156+
}
157+
148158
createInfo.enabledLayerCount = 1;
149159
createInfo.ppEnabledLayerNames = layers;
150160

151-
152161
VkResult result = vkCreateInstance(&createInfo, nullptr, &instance);
153162

154163
if (result != VK_SUCCESS)
@@ -167,7 +176,7 @@ bool Controller::Init()
167176

168177
if (callbackResult != VK_SUCCESS)
169178
{
170-
std::cout << "error: did not create callback succesfuly" << std::endl;
179+
throw std::runtime_error("Callback not created succesfuly");
171180
}
172181

173182
physicalDevice = VK_NULL_HANDLE;
@@ -176,7 +185,7 @@ bool Controller::Init()
176185

177186
if (deviceCount == 0)
178187
{
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");
180189
}
181190

182191
VkPhysicalDevice* devices = new VkPhysicalDevice[deviceCount]();
@@ -205,7 +214,7 @@ bool Controller::Init()
205214

206215
if (foundDiscreteGPU == false)
207216
{
208-
std::cout << "failed to find a discrete GPU" << std::endl;
217+
throw std::runtime_error("failed to find a discrete GPU");
209218
}
210219

211220
vkGetPhysicalDeviceFeatures(physicalDevice, &deviceFeatures);
@@ -217,28 +226,24 @@ bool Controller::Init()
217226
delete[] extensions;
218227

219228
CheckFormatPropertyType(VK_FORMAT_R32_SFLOAT, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
220-
221-
return true;
222229
}
223230

224-
bool Controller::Destroy()
231+
void Controller::Destroy()
225232
{
226233
auto vkDestroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
227234
vkDestroyDebugReportCallback(instance, callback, nullptr);
228235

229236
vkDestroyInstance(instance, nullptr);
230-
231-
return true;
232237
}
233238

234-
bool Controller::SetupQueue()
239+
void Controller::SetupQueue()
235240
{
236241
uint32_t queueFamilyCount = 0;
237242
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr);
238243

239244
if (queueFamilyCount == 0)
240245
{
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");
242247
}
243248

244249
VkQueueFamilyProperties* queueFamilies = new VkQueueFamilyProperties[queueFamilyCount]();
@@ -257,22 +262,20 @@ bool Controller::SetupQueue()
257262

258263
if (queueFamilyId == InvalidIndex)
259264
{
260-
std::cout << "failed to get all indicies" << std::endl;
265+
throw std::runtime_error("Failed to get queue family index");;
261266
}
262267

263268
delete[] queueFamilies;
264-
265-
return true;
266269
}
267270

268-
bool Controller::SetupDevice(const VkSurfaceKHR& surface)
271+
void Controller::SetupDevice(const VkSurfaceKHR& surface)
269272
{
270273
VkBool32 presentSupport = false;
271274
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyId, surface, &presentSupport);
272275

273276
if (presentSupport != true)
274277
{
275-
std::cout << "surface presetation not supported" << std::endl;
278+
throw std::runtime_error("surface presetation not supported");
276279
}
277280

278281
VkDeviceQueueCreateInfo queueCreateInfo = {};
@@ -309,7 +312,7 @@ bool Controller::SetupDevice(const VkSurfaceKHR& surface)
309312

310313
if (supported == false)
311314
{
312-
std::cout << "VK_KHR_swapchain device extension not supported" << std::endl;
315+
throw std::runtime_error("VK_KHR_swapchain device extension not supported");
313316
}
314317

315318
VkDeviceCreateInfo deviceCreateInfo = {};
@@ -326,15 +329,13 @@ bool Controller::SetupDevice(const VkSurfaceKHR& surface)
326329

327330
if (deviceResult != VK_SUCCESS)
328331
{
329-
std::cout << "failed to create device" << std::endl;
332+
throw std::runtime_error("failed to create device");
330333
}
331334

332335
delete[] availableDeviceExtensions;
333-
334-
return true;
335336
}
336337

337-
bool Controller::Configure(const VkSurfaceKHR& surface)
338+
void Controller::Configure(const VkSurfaceKHR& surface)
338339
{
339340
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &capabilities);
340341

@@ -344,10 +345,8 @@ bool Controller::Configure(const VkSurfaceKHR& surface)
344345

345346
if ((capabilities.supportedTransforms & transform) == 0)
346347
{
347-
std::cout << "Transform not supported" << std::endl;
348+
throw std::runtime_error("Transform not supported");
348349
}
349-
350-
return true;
351350
}
352351

353352
void Controller::PrintCapabilities() const
@@ -437,21 +436,15 @@ bool Controller::SurfaceFormatSupported(const VkSurfaceKHR& surface, VkFormat su
437436
return supported;
438437
}
439438

440-
bool Controller::CheckFormatPropertyType(VkFormat format, VkFormatFeatureFlagBits flags) const
439+
void Controller::CheckFormatPropertyType(VkFormat format, VkFormatFeatureFlagBits flags) const
441440
{
442441
VkFormatProperties formatProps;
443442
vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &formatProps);
444443

445-
if (formatProps.optimalTilingFeatures & flags)
446-
{
447-
return true;
448-
}
449-
else
444+
if ((formatProps.optimalTilingFeatures & flags) == 0)
450445
{
451446
throw std::runtime_error("Format property not optimal");
452447
}
453-
454-
return false;
455448
}
456449

457450
};

controller.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ class Controller
3737
Controller& operator=(const Controller&) = delete;
3838
Controller& operator=(Controller &&) = delete;
3939

40-
bool Init();
41-
bool SetupQueue();
42-
bool SetupDevice(const VkSurfaceKHR& surface);
43-
bool Destroy();
40+
void Init();
41+
void SetupQueue();
42+
void SetupDevice(const VkSurfaceKHR& surface);
43+
void Destroy();
4444

4545
inline VkPhysicalDevice& GetPhysicalDevice() { return physicalDevice; }
4646
inline VkDevice& GetDevice() { return device; }
4747
inline VkInstance& GetInstance() { return instance; }
4848

49-
bool Configure(const VkSurfaceKHR& surface);
49+
void Configure(const VkSurfaceKHR& surface);
5050
bool PresentModeSupported(const VkSurfaceKHR& surface, VkPresentModeKHR presentMode);
5151
bool SurfaceFormatSupported(const VkSurfaceKHR& surface, VkFormat surfaceFormat) const;
5252

@@ -58,7 +58,7 @@ class Controller
5858
inline uint32_t GetPresentQueueIndex() const { return presentQueueIndex; }
5959
inline uint32_t GetComputeQueueIndex() const { return computeQueueIndex; }
6060

61-
bool CheckFormatPropertyType(VkFormat format, VkFormatFeatureFlagBits flags) const;
61+
void CheckFormatPropertyType(VkFormat format, VkFormatFeatureFlagBits flags) const;
6262

6363
private:
6464
void PrintCapabilities() const;

0 commit comments

Comments
 (0)