Changeset 90a424f in opengl-game for vulkan-game.cpp
- Timestamp:
- Sep 16, 2019, 7:04:53 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- fe5c3ba
- Parents:
- c6fec84
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rc6fec84 r90a424f 93 93 createVulkanInstance(validationLayers); 94 94 setupDebugMessenger(); 95 createVulkanSurface(); 96 pickPhysicalDevice(); 95 97 } 96 98 … … 230 232 return VK_FALSE; 231 233 } 234 235 void VulkanGame::createVulkanSurface() { 236 if (gui->createVulkanSurface(instance, &surface) == RTWO_ERROR) { 237 throw runtime_error("failed to create window surface!"); 238 } 239 } 240 241 void VulkanGame::pickPhysicalDevice() { 242 uint32_t deviceCount = 0; 243 vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); 244 245 if (deviceCount == 0) { 246 throw runtime_error("failed to find GPUs with Vulkan support!"); 247 } 248 249 vector<VkPhysicalDevice> devices(deviceCount); 250 vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); 251 252 cout << endl << "Graphics cards:" << endl; 253 for (const VkPhysicalDevice& device : devices) { 254 if (isDeviceSuitable(device)) { 255 physicalDevice = device; 256 break; 257 } 258 } 259 cout << endl; 260 261 if (physicalDevice == VK_NULL_HANDLE) { 262 throw runtime_error("failed to find a suitable GPU!"); 263 } 264 } 265 266 bool VulkanGame::isDeviceSuitable(VkPhysicalDevice device) { 267 const vector<const char*> deviceExtensions = { 268 VK_KHR_SWAPCHAIN_EXTENSION_NAME 269 }; 270 271 VkPhysicalDeviceProperties deviceProperties; 272 vkGetPhysicalDeviceProperties(device, &deviceProperties); 273 274 cout << "Device: " << deviceProperties.deviceName << endl; 275 276 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(device, surface); 277 bool extensionsSupported = VulkanUtils::checkDeviceExtensionSupport(device, deviceExtensions); 278 bool swapChainAdequate = false; 279 280 if (extensionsSupported) { 281 SwapChainSupportDetails swapChainSupport = VulkanUtils::querySwapChainSupport(device, surface); 282 swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty(); 283 } 284 285 VkPhysicalDeviceFeatures supportedFeatures; 286 vkGetPhysicalDeviceFeatures(device, &supportedFeatures); 287 288 return indices.isComplete() && extensionsSupported && swapChainAdequate && supportedFeatures.samplerAnisotropy; 289 }
Note:
See TracChangeset
for help on using the changeset viewer.