249 lines
6.1 KiB
C++
249 lines
6.1 KiB
C++
#ifndef INITIALIZERS_H
|
|
#define INITIALIZERS_H
|
|
// Normal header
|
|
#include "types.h"
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
namespace vkinit {
|
|
VkCommandPoolCreateInfo commandPoolCreateInfo(
|
|
uint32_t queueFamilyIndex,
|
|
VkCommandPoolCreateFlags flags = 0
|
|
);
|
|
|
|
VkCommandBufferAllocateInfo commandBufferAllocateInfo(
|
|
VkCommandPool pool,
|
|
uint32_t count
|
|
);
|
|
|
|
VkFenceCreateInfo fenceCreateInfo(
|
|
VkFenceCreateFlags flags = 0
|
|
);
|
|
|
|
VkSemaphoreCreateInfo semaphoreCreateInfo (
|
|
VkSemaphoreCreateFlags flags = 0
|
|
);
|
|
|
|
VkCommandBufferBeginInfo commandBufferBeginInfo (
|
|
VkCommandBufferUsageFlags flags = 0
|
|
);
|
|
|
|
VkImageSubresourceRange imageSubresourceRange(
|
|
VkImageAspectFlags aspectMask
|
|
);
|
|
|
|
VkSemaphoreSubmitInfo semaphoreSubmitInfo(
|
|
VkPipelineStageFlags2 stageMask,
|
|
VkSemaphore semaphore
|
|
);
|
|
|
|
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
|
|
VkCommandBuffer cmd
|
|
);
|
|
|
|
VkSubmitInfo2 submitInfo(
|
|
VkCommandBufferSubmitInfo* cmd,
|
|
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
|
VkSemaphoreSubmitInfo* waitSemaphoreInfo
|
|
);
|
|
|
|
VkImageCreateInfo imageCreateInfo(
|
|
VkFormat format,
|
|
VkImageUsageFlags usageFlags,
|
|
VkExtent3D extent
|
|
);
|
|
|
|
VkImageViewCreateInfo imageViewCreateInfo(
|
|
VkFormat format,
|
|
VkImage image,
|
|
VkImageAspectFlags aspectFlags
|
|
);
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef INITIALIZERS_IMPL
|
|
#ifndef INITIALIZERS_IMPL_H
|
|
#define INITIALIZERS_IMPL_H
|
|
// Implementation
|
|
namespace vkinit {
|
|
// Todo :
|
|
// Switch structs to designated initializers
|
|
|
|
VkCommandPoolCreateInfo commandPoolCreateInfo(
|
|
uint32_t queueFamilyIndex,
|
|
VkCommandPoolCreateFlags flags
|
|
) {
|
|
VkCommandPoolCreateInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
|
info.pNext = nullptr;
|
|
info.queueFamilyIndex = queueFamilyIndex;
|
|
info.flags = flags;
|
|
return info;
|
|
}
|
|
|
|
VkCommandBufferAllocateInfo commandBufferAllocateInfo(
|
|
VkCommandPool pool,
|
|
uint32_t count
|
|
) {
|
|
VkCommandBufferAllocateInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
|
info.pNext = nullptr;
|
|
info.commandPool = pool;
|
|
info.commandBufferCount = count;
|
|
info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
return info;
|
|
}
|
|
|
|
VkFenceCreateInfo fenceCreateInfo(
|
|
VkFenceCreateFlags flags /*= 0 */
|
|
) {
|
|
VkFenceCreateInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
|
info.pNext = nullptr;
|
|
|
|
info.flags = flags;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkSemaphoreCreateInfo semaphoreCreateInfo (
|
|
VkSemaphoreCreateFlags flags /*= 0*/
|
|
) {
|
|
VkSemaphoreCreateInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
info.pNext = nullptr;
|
|
info.flags = flags;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkCommandBufferBeginInfo commandBufferBeginInfo (
|
|
VkCommandBufferUsageFlags flags /*= 0*/
|
|
) {
|
|
VkCommandBufferBeginInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
info.pNext = nullptr;
|
|
|
|
info.pInheritanceInfo = nullptr;
|
|
info.flags = flags;
|
|
return info;
|
|
}
|
|
|
|
VkImageSubresourceRange imageSubresourceRange(
|
|
VkImageAspectFlags aspectMask
|
|
) {
|
|
VkImageSubresourceRange subImage {};
|
|
subImage.aspectMask = aspectMask;
|
|
subImage.baseMipLevel = 0;
|
|
subImage.levelCount = VK_REMAINING_MIP_LEVELS;
|
|
subImage.baseArrayLayer = 0;
|
|
subImage.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
|
|
|
return subImage;
|
|
}
|
|
|
|
VkSemaphoreSubmitInfo semaphoreSubmitInfo(
|
|
VkPipelineStageFlags2 stageMask,
|
|
VkSemaphore semaphore
|
|
) {
|
|
VkSemaphoreSubmitInfo submitInfo{};
|
|
submitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;
|
|
submitInfo.pNext = nullptr;
|
|
submitInfo.semaphore = semaphore;
|
|
submitInfo.stageMask = stageMask;
|
|
submitInfo.deviceIndex = 0;
|
|
submitInfo.value = 1;
|
|
|
|
return submitInfo;
|
|
}
|
|
|
|
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
|
|
VkCommandBuffer cmd
|
|
) {
|
|
VkCommandBufferSubmitInfo info {};
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
|
|
info.pNext = nullptr;
|
|
info.commandBuffer = cmd;
|
|
info.deviceMask = 0;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkSubmitInfo2 submitInfo(
|
|
VkCommandBufferSubmitInfo* cmd,
|
|
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
|
VkSemaphoreSubmitInfo* waitSemaphoreInfo
|
|
) {
|
|
VkSubmitInfo2 info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2;
|
|
info.pNext = nullptr;
|
|
|
|
info.waitSemaphoreInfoCount = waitSemaphoreInfo == nullptr ? 0 : 1;
|
|
info.pWaitSemaphoreInfos = waitSemaphoreInfo;
|
|
|
|
info.signalSemaphoreInfoCount = signalSemaphoreInfo == nullptr ? 0 : 1;
|
|
info.pSignalSemaphoreInfos = signalSemaphoreInfo;
|
|
|
|
info.commandBufferInfoCount = 1;
|
|
info.pCommandBufferInfos = cmd;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkImageCreateInfo imageCreateInfo(
|
|
VkFormat format,
|
|
VkImageUsageFlags usageFlags,
|
|
VkExtent3D extent
|
|
) {
|
|
VkImageCreateInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
|
info.pNext = nullptr;
|
|
|
|
info.imageType = VK_IMAGE_TYPE_2D;
|
|
|
|
info.format = format;
|
|
info.extent = extent;
|
|
|
|
info.mipLevels = 1;
|
|
info.arrayLayers = 1;
|
|
|
|
//for MSAA. I won't be using it, so only 1 sample per pixel
|
|
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
info.usage = usageFlags;
|
|
|
|
return info;
|
|
}
|
|
|
|
// Switched to designated initializers,
|
|
// because it's more modern, and require less typing
|
|
|
|
VkImageViewCreateInfo imageViewCreateInfo(
|
|
VkFormat format,
|
|
VkImage image,
|
|
VkImageAspectFlags aspectFlags
|
|
) {
|
|
VkImageViewCreateInfo info = {
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
.pNext = nullptr,
|
|
.image = image,
|
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
|
.format = format,
|
|
.subresourceRange = {
|
|
.aspectMask = aspectFlags,
|
|
.baseMipLevel = 0,
|
|
.levelCount = 1,
|
|
.baseArrayLayer = 0,
|
|
.layerCount = 1,
|
|
}
|
|
};
|
|
|
|
return info;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|