sandbox
Loading...
Searching...
No Matches
validation_layers.hpp
1#ifndef LIBSBX_GRAPHICS_DEVICES_VALIDATION_LAYERS_HPP_
2#define LIBSBX_GRAPHICS_DEVICES_VALIDATION_LAYERS_HPP_
3
4#include <vector>
5
6#include <vulkan/vulkan.hpp>
7
8#include <libsbx/utility/target.hpp>
9
10namespace sbx::graphics {
11
13
14 static auto instance() -> std::vector<const char*> {
15 auto required_layers = std::vector<const char*>{};
16
17 if constexpr (utility::build_configuration_v == utility::build_configuration::debug) {
18 required_layers.push_back("VK_LAYER_KHRONOS_validation");
19
20 auto available_layer_count = std::uint32_t{0};
21 vkEnumerateInstanceLayerProperties(&available_layer_count, nullptr);
22
23 auto available_layers = std::vector<VkLayerProperties>{available_layer_count};
24 vkEnumerateInstanceLayerProperties(&available_layer_count, available_layers.data());
25
26 for (const auto* required_layer : required_layers) {
27 bool found = false;
28
29 for (const auto& available_layer : available_layers) {
30 if (std::strcmp(required_layer, available_layer.layerName) == 0) {
31 found = true;
32 break;
33 }
34 }
35
36 if (!found) {
37 throw std::runtime_error{"Required layer not available: " + std::string{required_layer}};
38 }
39 }
40 }
41
42 return required_layers;
43 }
44
45}; // struct validation_layers
46
47} // namespace sbx::graphics
48
49#endif // LIBSBX_GRAPHICS_DEVICES_VALIDATION_LAYERS_HPP_
Definition: instance.hpp:10
Definition: validation_layers.hpp:12