Skip to content
Snippets Groups Projects
Verified Commit 97631592 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

[#71] Reduced runtime errors but added some for required features and extensions

parent d22acb48
No related branches found
No related tags found
1 merge request!83Resolve "Refactor Pipeline Config and Manager"
Pipeline #27068 passed
......@@ -117,6 +117,10 @@ namespace vkcv {
featureFunction(features);
if (!checkSupport(features, required)) {
if (required) {
throw std::runtime_error("Required feature is not supported!");
}
return false;
}
......
......@@ -124,16 +124,17 @@ namespace vkcv
/**
* @brief All existing physical devices will be evaluated by deviceScore.
* @param instance The instance
* @return The optimal physical device
* @param physicalDevice The optimal physical device
* @return Returns if a suitable GPU is found as physical device
* @see Context.deviceScore
*/
vk::PhysicalDevice pickPhysicalDevice(vk::Instance& instance)
bool pickPhysicalDevice(const vk::Instance& instance, vk::PhysicalDevice& physicalDevice)
{
vk::PhysicalDevice phyDevice;
std::vector<vk::PhysicalDevice> devices = instance.enumeratePhysicalDevices();
const std::vector<vk::PhysicalDevice>& devices = instance.enumeratePhysicalDevices();
if (devices.empty()) {
throw std::runtime_error("failed to find GPUs with Vulkan support!");
vkcv_log(LogLevel::ERROR, "Failed to find GPUs with Vulkan support");
return false;
}
int max_score = -1;
......@@ -141,15 +142,16 @@ namespace vkcv
int score = deviceScore(device);
if (score > max_score) {
max_score = score;
phyDevice = device;
physicalDevice = device;
}
}
if (max_score == -1) {
throw std::runtime_error("failed to find a suitable GPU!");
vkcv_log(LogLevel::ERROR, "Failed to find a suitable GPU");
return false;
} else {
return true;
}
return phyDevice;
}
/**
......@@ -257,7 +259,11 @@ namespace vkcv
vk::Instance instance = vk::createInstance(instanceCreateInfo);
std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();
vk::PhysicalDevice physicalDevice = pickPhysicalDevice(instance);
vk::PhysicalDevice physicalDevice;
if (!pickPhysicalDevice(instance, physicalDevice)) {
throw std::runtime_error("Picking suitable GPU as physical device failed!");
}
FeatureManager featureManager (physicalDevice);
......
......@@ -395,6 +395,10 @@ m_physicalDevice.getFeatures2(&query)
extension.c_str());
delete[] clone;
if (required) {
throw std::runtime_error("Required extension is not supported!");
}
return false;
}
......
......@@ -148,7 +148,8 @@ namespace vkcv {
}
break;
default:
throw std::runtime_error("Invalid input for queue flag bits. Valid inputs are 'vk::QueueFlagBits::eGraphics', 'vk::QueueFlagBits::eCompute' and 'vk::QueueFlagBits::eTransfer'.");
vkcv_log(LogLevel::ERROR, "Invalid input for queue flag bits: %s", vk::to_string(qFlag).c_str());
break;
}
}
......
......@@ -73,12 +73,7 @@ namespace vkcv
* @param window of the current application
* @return chosen Extent for the surface
*/
vk::Extent2D chooseExtent(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR surface, const Window &window){
vk::SurfaceCapabilitiesKHR surfaceCapabilities;
if(physicalDevice.getSurfaceCapabilitiesKHR(surface,&surfaceCapabilities) != vk::Result::eSuccess){
throw std::runtime_error("cannot get surface capabilities. There is an issue with the surface.");
}
vk::Extent2D chooseExtent(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR surface, const Window &window) {
int fb_width, fb_height;
window.getFramebufferSize(fb_width, fb_height);
......@@ -86,9 +81,17 @@ namespace vkcv
static_cast<uint32_t>(fb_width),
static_cast<uint32_t>(fb_height)
};
extent2D.width = std::max(surfaceCapabilities.minImageExtent.width, std::min(surfaceCapabilities.maxImageExtent.width, extent2D.width));
extent2D.height = std::max(surfaceCapabilities.minImageExtent.height, std::min(surfaceCapabilities.maxImageExtent.height, extent2D.height));
vk::SurfaceCapabilitiesKHR surfaceCapabilities;
if(physicalDevice.getSurfaceCapabilitiesKHR(surface, &surfaceCapabilities) != vk::Result::eSuccess) {
vkcv_log(LogLevel::WARNING, "The capabilities of the surface can not be retrieved");
extent2D.width = std::max(MIN_SWAPCHAIN_SIZE, extent2D.width);
extent2D.height = std::max(MIN_SWAPCHAIN_SIZE, extent2D.height);
} else {
extent2D.width = std::max(surfaceCapabilities.minImageExtent.width, std::min(surfaceCapabilities.maxImageExtent.width, extent2D.width));
extent2D.height = std::max(surfaceCapabilities.minImageExtent.height, std::min(surfaceCapabilities.maxImageExtent.height, extent2D.height));
}
return extent2D;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment