Skip to content

Commit

Permalink
[error-handling] Replaced error check macros with exceptions.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes <[email protected]>
  • Loading branch information
IAmNotHanni committed Sep 17, 2020
1 parent fa960b1 commit 8af0155
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 458 deletions.
2 changes: 0 additions & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "inexor/vulkan-renderer/application.hpp"

#include "inexor/vulkan-renderer/error_handling.hpp"

#include <spdlog/async.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
Expand Down
22 changes: 6 additions & 16 deletions include/inexor/vulkan-renderer/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace inexor::vulkan_renderer {

class Application : public VulkanRenderer {
private:
std::string m_application_name;
std::string m_engine_name;

Expand All @@ -30,22 +29,13 @@ class Application : public VulkanRenderer {
/// @brief file_name [in] The TOML configuration file.
/// @note It was collectively decided not to use JSON for configuration files.
void load_toml_configuration_file(const std::string &file_name);

VkResult load_textures();

VkResult load_shaders();

VkResult load_octree_geometry();

void load_textures();
void load_shaders();
void load_octree_geometry();
void update_imgui_overlay();

VkResult check_application_specific_features();

/// @brief Implementation of the uniform buffer update method.
/// @param current_image [in] The current image index.
VkResult update_uniform_buffers();

VkResult update_mouse_input();
void check_application_specific_features();
void update_uniform_buffers();
void update_mouse_input();

// TODO: Refactor!
double m_cursor_x, m_cursor_y;
Expand Down
49 changes: 15 additions & 34 deletions include/inexor/vulkan-renderer/availability_checks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,56 @@ namespace inexor::vulkan_renderer {
class AvailabilityChecksManager {
private:
std::uint32_t m_available_instance_extensions{0};

std::uint32_t m_available_instance_layers{0};

std::uint32_t m_available_device_layers{0};

std::uint32_t m_available_device_extensions{0};

std::vector<VkExtensionProperties> m_instance_extensions_cache;

std::vector<VkLayerProperties> m_instance_layers_cache;

std::vector<VkLayerProperties> m_device_layer_properties_cache;

std::vector<VkExtensionProperties> m_device_extensions_cache;

VkResult create_instance_layers_cache();

VkResult create_device_layers_cache(const VkPhysicalDevice &graphics_card);

VkResult create_device_extensions_cache(const VkPhysicalDevice &graphics_card);

VkResult create_instance_extensions_cache();
void create_instance_layers_cache();
void create_device_layers_cache(const VkPhysicalDevice &graphics_card);
void create_device_extensions_cache(const VkPhysicalDevice &graphics_card);
void create_instance_extensions_cache();

public:
AvailabilityChecksManager() = default;

~AvailabilityChecksManager() = default;

/// @brief Checks if a certain Vulkan instance layer is available on the system.
/// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkEnumerateInstanceLayerProperties.html
/// @param instance_layer_name The name of the Vulkan instance layer.
/// @return true if the Vulkan instance layer is available, false otherwise.
/// @note Available instance layers can be enabled by passing them as parameter during Vulkan instance creation.
/// @param instance_layer_name [in] The name of the Vulkan instance layer.
/// @return true if the Vulkan instance layer is available, false otherwise.
[[nodiscard]] bool has_instance_layer(const std::string &instance_layer_name);

/// @brief Checks if a certain Vulkan instance extension is available on the system.
/// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkEnumerateInstanceExtensionProperties.html
/// @param instance_extension_name The name of the Vulkan instance extension.
/// @return true if the Vulkan instance extension is available, false otherwise.
/// @note Available instance extensions can be enabled by passing them as parameter during Vulkan instance creation.
/// @param instance_extension_name [in] The name of the Vulkan instance extension.
/// @return True if the Vulkan instance extension is available, false otherwise.
[[nodiscard]] bool has_instance_extension(const std::string &instance_extension_name);

/// @brief Checks if a certain Vulkan device layer is available on the system.
/// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkEnumerateDeviceLayerProperties.html
/// @note Device layers and device extensions are coupled to a certain graphics card which needs to be specified as
/// parameter.
/// @param graphics_card The selected graphics card.
/// @param device_layer_name The name of the Vulkan device layer.
/// @return true if the Vulkan device layer is available, false otherwise.
/// @note Available device layers can be enabled by passing them as a parameter during Vulkan device creation.
/// parameter. Available device layers can be enabled by passing them as a parameter during Vulkan device creation.
/// @param graphics_card [in] The selected graphics card.
/// @param device_layer_name [in] The name of the Vulkan device layer.
/// @return True if the Vulkan device layer is available, false otherwise.
[[nodiscard]] bool has_device_layer(const VkPhysicalDevice &graphics_card, const std::string &device_layer_name);

/// @brief Checks if a certain Vulkan device extension is available on the system.
/// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkEnumerateDeviceExtensionProperties.html
/// Available device extensions can be enabled by passing them as a parameter during Vulkan device creation.
/// @param graphics_card [in] The selected graphics card.
/// @param device_extension_name [in] The name of the Vulkan device extension.
/// @return true if the Vulkan device extension is available, false otherwise.
/// @note Available device extensions can be enabled by passing them as a parameter during Vulkan device creation.
/// @note Device layers and device extensions are coupled to a certain graphics card which needs to be specified as
/// parameter.
/// @return True if the Vulkan device extension is available, false otherwise.
[[nodiscard]] bool has_device_extension(const VkPhysicalDevice &graphics_card,
const std::string &device_extension_name);

/// @brief Checks if presentation is available for a certain combination of graphics card and window surface.
/// The present mode describes how the rendered image will be presented on the screen.
/// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkGetPhysicalDeviceSurfaceSupportKHR.html
/// @param graphics_card [in] The selected graphics card.
/// @param surface [surface] The window surface.
/// @return true if presentation is available, false otherwise.
/// @return True if presentation is available, false otherwise.
[[nodiscard]] bool has_presentation(const VkPhysicalDevice &graphics_card, const VkSurfaceKHR &surface);

/// @brief Checks if swapchain is available for a certain graphics card.
Expand Down
30 changes: 0 additions & 30 deletions include/inexor/vulkan-renderer/error_handling.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set(INEXOR_SOURCE_FILES
vulkan-renderer/bezier_curve.cpp
vulkan-renderer/camera.cpp
vulkan-renderer/debug_callback.cpp
vulkan-renderer/error_handling.cpp
vulkan-renderer/fps_counter.cpp
vulkan-renderer/frame_graph.cpp
vulkan-renderer/gpu_info.cpp
Expand Down
53 changes: 16 additions & 37 deletions src/vulkan-renderer/application.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "inexor/vulkan-renderer/application.hpp"

#include "inexor/vulkan-renderer/debug_callback.hpp"
#include "inexor/vulkan-renderer/error_handling.hpp"
#include "inexor/vulkan-renderer/octree_gpu_vertex.hpp"
#include "inexor/vulkan-renderer/standard_ubo.hpp"
#include "inexor/vulkan-renderer/tools/cla_parser.hpp"
Expand Down Expand Up @@ -113,7 +112,7 @@ void Application::load_toml_configuration_file(const std::string &file_name) {
// TODO: Load more info from TOML file.
}

VkResult Application::load_textures() {
void Application::load_textures() {
assert(m_device->device());
assert(m_device->physical_device());
assert(m_device->allocator());
Expand All @@ -128,11 +127,9 @@ VkResult Application::load_textures() {
wrapper::CpuTexture cpu_texture(texture_file, texture_name);
m_textures.emplace_back(*m_device, cpu_texture);
}

return VK_SUCCESS;
}

VkResult Application::load_shaders() {
void Application::load_shaders() {
assert(m_device->device());

spdlog::debug("Loading vertex shaders.");
Expand Down Expand Up @@ -167,11 +164,9 @@ VkResult Application::load_shaders() {
}

spdlog::debug("Loading shaders finished.");

return VK_SUCCESS;
}

VkResult Application::load_octree_geometry() {
void Application::load_octree_geometry() {
spdlog::debug("Creating octree geometry.");

std::shared_ptr<world::Cube> cube =
Expand All @@ -195,11 +190,9 @@ VkResult Application::load_octree_geometry() {
}
}
}

return VK_SUCCESS;
}

VkResult Application::check_application_specific_features() {
void Application::check_application_specific_features() {
assert(m_device->physical_device());

VkPhysicalDeviceFeatures graphics_card_features;
Expand All @@ -214,8 +207,6 @@ VkResult Application::check_application_specific_features() {
}

// TODO: Add more checks if necessary.

return VK_SUCCESS;
}

Application::Application(int argc, char **argv) {
Expand Down Expand Up @@ -290,15 +281,12 @@ Application::Application(int argc, char **argv) {
vkGetInstanceProcAddr(m_instance->instance(), "vkCreateDebugReportCallbackEXT"));

if (vkCreateDebugReportCallbackEXT) {
// Create the debug report callback.
VkResult result = vkCreateDebugReportCallbackEXT(m_instance->instance(), &debug_report_ci, nullptr,
&m_debug_report_callback);
if (VK_SUCCESS == result) {
spdlog::debug("Creating Vulkan debug callback.");
m_debug_report_callback_initialised = true;
} else {
vulkan_error_check(result);
if (vkCreateDebugReportCallbackEXT(m_instance->instance(), &debug_report_ci, nullptr,
&m_debug_report_callback) != VK_SUCCESS) {
throw std::runtime_error("Error: vkCreateDebugReportCallbackEXT failed!");
}
spdlog::debug("Creating Vulkan debug callback.");
m_debug_report_callback_initialised = true;
} else {
spdlog::error("vkCreateDebugReportCallbackEXT is a null-pointer! Function not available.");
}
Expand Down Expand Up @@ -381,17 +369,13 @@ Application::Application(int argc, char **argv) {
std::make_unique<wrapper::Device>(m_instance->instance(), m_surface->get(),
enable_debug_marker_device_extension, use_distinct_data_transfer_queue);

VkResult result = check_application_specific_features();
vulkan_error_check(result);
check_application_specific_features();

m_swapchain = std::make_unique<wrapper::Swapchain>(*m_device, m_surface->get(), m_window->width(),
m_window->height(), m_vsync_enabled, "Standard swapchain");

result = load_textures();
vulkan_error_check(result);

result = load_shaders();
vulkan_error_check(result);
load_textures();
load_shaders();

m_command_pool = std::make_unique<wrapper::CommandPool>(*m_device, m_device->graphics_queue_family_index());

Expand Down Expand Up @@ -429,18 +413,17 @@ Application::Application(int argc, char **argv) {
descriptor_writes,
"Default descriptor"});

result = load_octree_geometry();
load_octree_geometry();
generate_octree_indices();
vulkan_error_check(result);

spdlog::debug("Vulkan initialisation finished.");

spdlog::debug("Showing window.");

m_window->show();
recreate_swapchain();
}

VkResult Application::update_uniform_buffers() {
void Application::update_uniform_buffers() {
float time = m_time_step.time_step_since_initialisation();

UniformBufferObject ubo{};
Expand All @@ -454,11 +437,9 @@ VkResult Application::update_uniform_buffers() {

// TODO: Don't use vector of uniform buffers.
m_uniform_buffers[0].update(&ubo, sizeof(ubo));

return VK_SUCCESS;
}

VkResult Application::update_mouse_input() {
void Application::update_mouse_input() {
double current_cursor_x{0.0};
double current_cursor_y{0.0};

Expand All @@ -478,8 +459,6 @@ VkResult Application::update_mouse_input() {

m_cursor_x = current_cursor_x;
m_cursor_y = current_cursor_y;

return VK_SUCCESS;
}

void Application::update_imgui_overlay() {
Expand Down
Loading

0 comments on commit 8af0155

Please sign in to comment.