Changeset fe5c3ba in opengl-game


Ignore:
Timestamp:
Sep 22, 2019, 2:28:22 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
a0c5f28
Parents:
90a424f
Message:

In vulkangame, change the pickPhysicalDevice() and isDeviceSuitable() functions to take the deviceExtensions list as a parameter

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r90a424f rfe5c3ba  
    9090      "VK_LAYER_KHRONOS_validation"
    9191   };
     92   const vector<const char*> deviceExtensions = {
     93      VK_KHR_SWAPCHAIN_EXTENSION_NAME
     94   };
    9295
    9396   createVulkanInstance(validationLayers);
    9497   setupDebugMessenger();
    9598   createVulkanSurface();
    96    pickPhysicalDevice();
     99   pickPhysicalDevice(deviceExtensions);
    97100}
    98101
     
    239242}
    240243
    241 void VulkanGame::pickPhysicalDevice() {
     244void VulkanGame::pickPhysicalDevice(const vector<const char*>& deviceExtensions) {
    242245   uint32_t deviceCount = 0;
    243246   vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
     
    252255   cout << endl << "Graphics cards:" << endl;
    253256   for (const VkPhysicalDevice& device : devices) {
    254       if (isDeviceSuitable(device)) {
     257      if (isDeviceSuitable(device, deviceExtensions)) {
    255258         physicalDevice = device;
    256259         break;
     
    264267}
    265268
    266 bool VulkanGame::isDeviceSuitable(VkPhysicalDevice device) {
    267    const vector<const char*> deviceExtensions = {
    268       VK_KHR_SWAPCHAIN_EXTENSION_NAME
    269    };
    270 
     269bool VulkanGame::isDeviceSuitable(VkPhysicalDevice device, const vector<const char*>& deviceExtensions) {
    271270   VkPhysicalDeviceProperties deviceProperties;
    272271   vkGetPhysicalDeviceProperties(device, &deviceProperties);
  • vulkan-game.hpp

    r90a424f rfe5c3ba  
    2626      VkInstance instance;
    2727      VkDebugUtilsMessengerEXT debugMessenger;
    28       VkSurfaceKHR surface;
     28      VkSurfaceKHR surface; // TODO: Change the variable name to vulkanSurface
    2929      VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
    3030
     
    3838      void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
    3939      void createVulkanSurface();
    40       void pickPhysicalDevice();
    41       bool isDeviceSuitable(VkPhysicalDevice device);
     40      void pickPhysicalDevice(const vector<const char*>& deviceExtensions);
     41      bool isDeviceSuitable(VkPhysicalDevice device, const vector<const char*>& deviceExtensions);
    4242
    4343      static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
  • vulkan-utils.cpp

    r90a424f rfe5c3ba  
    11#include "vulkan-utils.hpp"
    22
     3#include <algorithm>
    34#include <set>
     5#include <stdexcept>
    46#include <string>
    57
     
    5254}
    5355
    54 QueueFamilyIndices VulkanUtils::findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface) {
     56QueueFamilyIndices VulkanUtils::findQueueFamilies(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface) {
    5557   QueueFamilyIndices indices;
    5658
    5759   uint32_t queueFamilyCount = 0;
    58    vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
     60   vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, nullptr);
    5961
    6062   vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
    61    vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data());
     63   vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyCount, queueFamilies.data());
    6264
    6365   int i = 0;
     
    6870
    6971      VkBool32 presentSupport = false;
    70       vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
     72      vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, i, surface, &presentSupport);
    7173
    7274      if (queueFamily.queueCount > 0 && presentSupport) {
     
    8486}
    8587
    86 bool VulkanUtils::checkDeviceExtensionSupport(VkPhysicalDevice device, const vector<const char*>& deviceExtensions) {
     88bool VulkanUtils::checkDeviceExtensionSupport(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions) {
    8789   uint32_t extensionCount;
    88    vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
     90   vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extensionCount, nullptr);
    8991
    9092   vector<VkExtensionProperties> availableExtensions(extensionCount);
    91    vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data());
     93   vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extensionCount, availableExtensions.data());
    9294
    9395   set<string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());
     
    100102}
    101103
    102 SwapChainSupportDetails VulkanUtils::querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface) {
     104SwapChainSupportDetails VulkanUtils::querySwapChainSupport(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface) {
    103105   SwapChainSupportDetails details;
    104106
    105    vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);
     107   vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &details.capabilities);
    106108
    107109   uint32_t formatCount;
    108    vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
     110   vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, nullptr);
    109111
    110112   if (formatCount != 0) {
    111113      details.formats.resize(formatCount);
    112       vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());
     114      vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &formatCount, details.formats.data());
    113115   }
    114116
    115117   uint32_t presentModeCount;
    116    vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
     118   vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, &presentModeCount, nullptr);
    117119
    118120   if (presentModeCount != 0) {
    119121      details.presentModes.resize(presentModeCount);
    120       vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());
     122      vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, &presentModeCount, details.presentModes.data());
    121123   }
    122124
  • vulkan-utils.hpp

    r90a424f rfe5c3ba  
    3737            const VkAllocationCallbacks* pAllocator);
    3838
    39       static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface);
    40       static bool checkDeviceExtensionSupport(VkPhysicalDevice device, const vector<const char*>& deviceExtensions);
    41       static SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
     39      static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
     40      static bool checkDeviceExtensionSupport(VkPhysicalDevice physicalDevice, const vector<const char*>& deviceExtensions);
     41      static SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
    4242};
    4343
Note: See TracChangeset for help on using the changeset viewer.