check for device swap chain details when picking physical device
This commit is contained in:
parent
15c6af1070
commit
a93c36db4e
1 changed files with 36 additions and 2 deletions
38
main.cpp
38
main.cpp
|
|
@ -19,6 +19,12 @@ const std::vector<const char*> validationLayers = {
|
|||
#endif
|
||||
};
|
||||
|
||||
struct SwapChainSupportDetails {
|
||||
VkSurfaceCapabilitiesKHR capabilities {};
|
||||
std::vector<VkSurfaceFormatKHR> formats;
|
||||
std::vector<VkPresentModeKHR> presentModes;
|
||||
};
|
||||
|
||||
class Application {
|
||||
public:
|
||||
void run() {
|
||||
|
|
@ -135,7 +141,7 @@ private:
|
|||
if (!mPhysicalDevice) throw std::runtime_error("no suitable gpu");
|
||||
}
|
||||
|
||||
static bool isDeviceSuitable(VkPhysicalDevice device) {
|
||||
bool isDeviceSuitable(VkPhysicalDevice device) {
|
||||
VkPhysicalDeviceProperties properties;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
|
||||
|
|
@ -145,10 +151,16 @@ private:
|
|||
// if (properties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) return false;
|
||||
if (!features.geometryShader) return false;
|
||||
if (!checkDeviceExtensions(device)) return false;
|
||||
if (!checkDeviceSwapChain(device)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkDeviceSwapChain(VkPhysicalDevice device) {
|
||||
SwapChainSupportDetails details = querySwapChainSupportDetails(device);
|
||||
return !(details.presentModes.empty() || details.formats.empty());
|
||||
}
|
||||
|
||||
static bool checkDeviceExtensions(VkPhysicalDevice device) {
|
||||
uint32_t extensionsCount = 0;
|
||||
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionsCount, nullptr);
|
||||
|
|
@ -198,6 +210,28 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
SwapChainSupportDetails querySwapChainSupportDetails(VkPhysicalDevice device) {
|
||||
SwapChainSupportDetails details;
|
||||
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, mSurface, &details.capabilities);
|
||||
|
||||
uint32_t formatCount = 0;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, mSurface, &formatCount, nullptr);
|
||||
if (formatCount != 0) {
|
||||
details.formats.resize(formatCount);
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, mSurface, &formatCount, details.formats.data());
|
||||
}
|
||||
|
||||
uint32_t modeCount = 0;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, mSurface, &modeCount, nullptr);
|
||||
if (modeCount != 0) {
|
||||
details.presentModes.resize(modeCount);
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, mSurface, &modeCount, details.presentModes.data());
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
void createLogicalDevice() {
|
||||
float queuePriority = 1.f;
|
||||
|
||||
|
|
@ -218,7 +252,7 @@ private:
|
|||
std::vector<VkDeviceQueueCreateInfo> queues = { graphicsQueueCreateInfos };
|
||||
|
||||
if (mPresentationQueueFamilyIndex != mGraphicsQueueFamilyIndex) {
|
||||
queues.push_back(graphicsQueueCreateInfos);
|
||||
queues.push_back(presentationQueueCreateInfos);
|
||||
}
|
||||
|
||||
VkPhysicalDeviceFeatures features {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue