PeriDyno 1.0.0
Loading...
Searching...
No Matches
VkContext.h
Go to the documentation of this file.
1#pragma once
2#include "Platform.h"
3#include "VulkanBuffer.h"
4#include "VulkanTools.h"
5#include "vulkan/vulkan.h"
6#include <algorithm>
7#include <assert.h>
8#include <exception>
9#include <map>
10
11VK_DEFINE_HANDLE(VmaAllocator)
12VK_DEFINE_HANDLE(VmaPool)
13
14namespace dyno {
15
17 {
18 public:
19 explicit VkContext(VkPhysicalDevice physicalDevice);
20 ~VkContext();
21
22 VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector<const char *> enabledExtensions, void *pNextChain, bool useSwapChain = true, VkQueueFlags requestedQueueTypes = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT);
23
25
26 inline VkDevice deviceHandle() { return logicalDevice; }
27 inline VkQueue graphicsQueueHandle() { return graphicsQueue; }
28 inline VkQueue computeQueueHandle() { return computeQueue; }
29 inline VkQueue transferQueueHandle() { return transferQueue; }
30
31 inline VkPhysicalDevice physicalDeviceHandle() { return physicalDevice; }
32
33 inline VkPipelineCache pipelineCacheHandle() { return pipelineCache; }
34
35 // Check whether the compute queue family is distinct from the graphics queue family
37
38 uint32_t getMemoryType(uint32_t typeBits, VkMemoryPropertyFlags properties, VkBool32 *memTypeFound = nullptr) const;
39 uint32_t getQueueFamilyIndex(VkQueueFlagBits queueFlags) const;
40 VkResult createBuffer(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize size, VkBuffer *buffer, VkDeviceMemory *memory, void *data = nullptr);
41 VkResult createBuffer(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, std::shared_ptr<vks::Buffer> &buffer, VkDeviceSize size, const void *data = nullptr);
42 VkResult createBuffer(uint32_t poolType, std::shared_ptr<vks::Buffer> &buffer, const void *data = nullptr);
43 VkResult createMemoryPool(VkInstance instance, uint32_t apiVerion);
44 void copyBuffer(vks::Buffer *src, vks::Buffer *dst, VkQueue queue, VkBufferCopy *copyRegion = nullptr);
45 VkCommandPool createCommandPool(uint32_t queueFamilyIndex, VkCommandPoolCreateFlags createFlags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
46 VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, VkCommandPool pool, bool begin = false);
47 VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false);
48 void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, VkCommandPool pool, bool free = true);
49 void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, bool free = true);
50 bool extensionSupported(std::string extension);
51 VkFormat getSupportedDepthFormat(bool checkSamplingSupport);
52
53 public:
55 VkPhysicalDevice physicalDevice;
57 VkDevice logicalDevice;
59 VkPhysicalDeviceProperties properties;
61 VkPhysicalDeviceFeatures features;
63 VkPhysicalDeviceFeatures enabledFeatures;
65 VkPhysicalDeviceMemoryProperties memoryProperties;
67 std::vector<VkQueueFamilyProperties> queueFamilyProperties;
69 std::vector<std::string> supportedExtensions;
71 VkCommandPool commandPool = VK_NULL_HANDLE;
72
74 VkQueue computeQueue;
77 bool enableDebugMarkers = false;
79
80 // Pipeline cache object
81 VkPipelineCache pipelineCache;
82
83 struct
84 {
85 uint32_t graphics;
86 uint32_t compute;
87 uint32_t transfer;
89 operator VkDevice() const
90 {
91 return logicalDevice;
92 };
93
101
103 {
104 VmaPool pool;
105 int32_t usage;
106 };
107
108 std::map<VkFlags, MemoryPoolInfo> poolMap;
109 VmaAllocator g_Allocator;
110 bool useMemoryPool = false;
111 };
112}
VkResult createBuffer(VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize size, VkBuffer *buffer, VkDeviceMemory *memory, void *data=nullptr)
VkCommandPool commandPool
Default command pool for the graphics queue family index.
Definition VkContext.h:71
bool extensionSupported(std::string extension)
uint32_t graphics
Definition VkContext.h:85
std::vector< std::string > supportedExtensions
List of extensions supported by the device.
Definition VkContext.h:69
VkQueue computeQueue
Definition VkContext.h:74
VkPipelineCache pipelineCacheHandle()
Definition VkContext.h:33
uint32_t getQueueFamilyIndex(VkQueueFlagBits queueFlags) const
void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, VkCommandPool pool, bool free=true)
VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, VkCommandPool pool, bool begin=false)
VkPhysicalDeviceFeatures features
Features of the physical device that an application can use to check if a feature is supported.
Definition VkContext.h:61
VkContext(VkPhysicalDevice physicalDevice)
Definition VkContext.cpp:12
VkPhysicalDevice physicalDeviceHandle()
Definition VkContext.h:31
struct dyno::VkContext::@247250360024255345354242335264053265034214002126 queueFamilyIndices
VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector< const char * > enabledExtensions, void *pNextChain, bool useSwapChain=true, VkQueueFlags requestedQueueTypes=VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT)
bool enableDebugMarkers
Set to true when the debug marker extension is detected.
Definition VkContext.h:77
VkCommandPool createCommandPool(uint32_t queueFamilyIndex, VkCommandPoolCreateFlags createFlags=VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)
VkQueue graphicsQueue
Definition VkContext.h:73
uint32_t getMemoryType(uint32_t typeBits, VkMemoryPropertyFlags properties, VkBool32 *memTypeFound=nullptr) const
Definition VkContext.cpp:87
VkQueue transferQueueHandle()
Definition VkContext.h:29
void copyBuffer(vks::Buffer *src, vks::Buffer *dst, VkQueue queue, VkBufferCopy *copyRegion=nullptr)
uint32_t transfer
Definition VkContext.h:87
VkPhysicalDevice physicalDevice
Physical device representation.
Definition VkContext.h:55
VkQueue transferQueue
Definition VkContext.h:75
VkResult createMemoryPool(VkInstance instance, uint32_t apiVerion)
VkPipelineCache pipelineCache
Contains queue family indices.
Definition VkContext.h:81
VkPhysicalDeviceMemoryProperties memoryProperties
Memory types and heaps of the physical device.
Definition VkContext.h:65
uint32_t compute
Definition VkContext.h:86
bool isComputeQueueSpecial()
Definition VkContext.cpp:71
VkPhysicalDeviceProperties properties
Properties of the physical device including limits that the application can check against.
Definition VkContext.h:59
VkPhysicalDeviceFeatures enabledFeatures
Features that have been enabled for use on the physical device.
Definition VkContext.h:63
VmaAllocator g_Allocator
Definition VkContext.h:109
VkQueue graphicsQueueHandle()
Definition VkContext.h:27
void createPipelineCache()
std::vector< VkQueueFamilyProperties > queueFamilyProperties
Queue family properties of the physical device.
Definition VkContext.h:67
std::map< VkFlags, MemoryPoolInfo > poolMap
Definition VkContext.h:108
VkFormat getSupportedDepthFormat(bool checkSamplingSupport)
VkDevice deviceHandle()
Definition VkContext.h:26
VkQueue computeQueueHandle()
Definition VkContext.h:28
VkDevice logicalDevice
Logical device representation (application's view of the device)
Definition VkContext.h:57
Encapsulates access to a Vulkan buffer backed up by device memory.
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25