aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/VulkanDevice.hpp
blob: d4aff6c847242f6778de482cebec2aa4b077a99e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Vulkan device class
*
* Encapsulates a physical Vulkan device and it's logical representation
*
* Copyright (C) 2016-2018 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#pragma once

#include "vke.hpp"
#include "phyInfos.hpp"

namespace vke
{
    struct device_t
    {
        VkPhysicalDevice            phy;
        VkDevice                    dev;
        VkPhysicalDeviceProperties  properties;
        VkPhysicalDeviceFeatures    features;
        VkPhysicalDeviceFeatures    enabledFeatures;
        VkPhysicalDeviceMemoryProperties    memoryProperties;
        std::vector<VkQueueFamilyProperties>queueFamilyProperties;

        VkCommandPool   commandPool     = VK_NULL_HANDLE;
        VkPipelineCache pipelineCache   = VK_NULL_HANDLE;
        bool            savePLCache     = true;

        VkQueue queue;

        struct {
            uint32_t graphics;
            uint32_t compute;
        } queueFamilyIndices;

        device_t(vkPhyInfo* phyInfos, const std::vector<const char *> &devLayers);
        ~device_t();

        uint32_t getMemoryType(uint32_t typeBits, VkMemoryPropertyFlags properties, VkBool32 *memTypeFound = nullptr);
        VkFormat getSuitableDepthFormat ();
        uint32_t getQueueFamilyIndex(VkQueueFlagBits queueFlags);

        VkCommandPool createCommandPool(uint32_t queueFamilyIndex,
                                        VkCommandPoolCreateFlags createFlags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
        VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false);

        void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, bool free = true);
        VkSemaphore createSemaphore ();
        VkFence createFence (bool signaled = false);
        void destroyFence (VkFence fence);
        void destroySemaphore (VkSemaphore semaphore);
        VkPipelineShaderStageCreateInfo loadShader(std::string filename, VkShaderStageFlagBits stage);
    };
}