Kale
Loading...
Searching...
No Matches
Extensions.hpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#ifdef KALE_VULKAN
20
21#include <string>
22#include <vector>
23#include <functional>
24#include <algorithm>
25
26namespace Kale::Vulkan {
27
37 template <typename T> std::vector<const char*> getExtensions(const std::vector<T>& availableExtensions,
38 const std::vector<std::string>& requiredExtensions, const std::vector<std::string>& requestedExtensions,
39 std::function<std::string (const T&)> mappingFn) {
40
41 // Filter the extensions out
42 std::vector<const char*> extensions;
43
44 // Find all required extensions
45 for (const std::string& requiredExtension : requiredExtensions) {
46
47 // If a required extension isn't found then throw an error
48 if (std::find_if(availableExtensions.begin(), availableExtensions.end(), [&](const T& availableExtension) {
49 return requiredExtension == mappingFn(availableExtension);
50 }) == availableExtensions.end())
51 throw std::runtime_error("Unable to find required extension - " + requiredExtension);
52
53 // Add the extension
54 extensions.push_back(requiredExtension.c_str());
55 }
56
57 // Find requested extensions
58 for (const std::string& requestedExtension : requestedExtensions) {
59
60 // Skip this extension if it's not found
61 if (std::find_if(availableExtensions.begin(), availableExtensions.end(), [&](const T& availableExtension) {
62 return requestedExtension == mappingFn(availableExtension);
63 }) == availableExtensions.end())
64 continue;
65
66 // If found add the extension
67 extensions.push_back(requestedExtension.c_str());
68 }
69
70 // Return our processed extensions
71 return extensions;
72 }
73
77 const inline std::vector<std::string> requiredInstanceExtensions{
78 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
79 };
80
84 const inline std::vector<std::string> requestedInstanceExtensions = {
85 #ifdef KALE_DEBUG
86 VK_EXT_DEBUG_UTILS_EXTENSION_NAME // Debug Utils, not a necessity but is nice in debug mode
87 #endif
88 };
89
94 const inline std::vector<std::string> requiredDeviceExtensions = {
95 VK_KHR_SWAPCHAIN_EXTENSION_NAME
96 };
97
101 const inline std::vector<std::string> requestedDeviceExtensions = {
102 "VK_KHR_portability_subset" // Specification states that if supported must be added
103 };
104
105 #ifdef KALE_DEBUG
106
110 const inline std::vector<std::string> requiredValidationLayers = {
111 "VK_LAYER_KHRONOS_validation"
112 };
113
117 const inline std::vector<std::string> requestedValidationLayers = {
118 // Empty for now
119 };
120
121 #endif
122}
123
124#endif
const std::vector< std::string > requestedInstanceExtensions
std::vector< const char * > getExtensions(const std::vector< T > &availableExtensions, const std::vector< std::string > &requiredExtensions, const std::vector< std::string > &requestedExtensions, std::function< std::string(const T &)> mappingFn)
const std::vector< std::string > requiredInstanceExtensions
const std::vector< std::string > requestedDeviceExtensions
const std::vector< std::string > requiredDeviceExtensions