213 lines
5.8 KiB
C++
213 lines
5.8 KiB
C++
#include <vk_initializers.h>
|
|
#include <vulkan/vk_enum_string_helper.h>
|
|
#include "trash_test.hpp"
|
|
|
|
nlohmann::json DATA = nlohmann::json::parse(R"(
|
|
{
|
|
"VkSemaphoreCreateInfo": {
|
|
"draw": {
|
|
"sType": 9
|
|
}
|
|
},
|
|
"VkFenceCreateInfo": {
|
|
"draw": {
|
|
"sType": 8
|
|
}
|
|
},
|
|
"VkImageViewCreateInfo": {
|
|
"draw": {
|
|
"sType": 15,
|
|
"viewType": 1,
|
|
"subresourceRange.baseMipLevel": 0,
|
|
"subresourceRange.levelCount": 1,
|
|
"subresourceRange.baseArrayLayer": 0,
|
|
"subresourceRange.layerCount": 1
|
|
}
|
|
}
|
|
}
|
|
)");
|
|
|
|
template<typename COMPONENT> COMPONENT load(nlohmann::json &data, const std::string& profile) {
|
|
COMPONENT result{};
|
|
auto& type_stuff = data[NameOf<COMPONENT>::name];
|
|
auto& profile_data = type_stuff[profile];
|
|
nlohmann::from_json(profile_data, result);
|
|
return result;
|
|
}
|
|
|
|
|
|
VkCommandPoolCreateInfo vkinit::command_pool_create_info(uint32_t queueFamilyIndex,
|
|
VkCommandPoolCreateFlags flags /*= 0*/)
|
|
{
|
|
VkCommandPoolCreateInfo info = {};
|
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
|
info.pNext = nullptr;
|
|
info.queueFamilyIndex = queueFamilyIndex;
|
|
info.flags = flags;
|
|
return info;
|
|
}
|
|
|
|
|
|
VkCommandBufferAllocateInfo vkinit::command_buffer_allocate_info(
|
|
VkCommandPool pool, uint32_t count /*= 1*/)
|
|
{
|
|
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 vkinit::fence_create_info(VkFenceCreateFlags flags /*=0*/)
|
|
{
|
|
auto info = load<VkFenceCreateInfo>(DATA, "draw");
|
|
info.flags = flags;
|
|
return info;
|
|
}
|
|
|
|
VkSemaphoreCreateInfo vkinit::semaphore_create_info(VkSemaphoreCreateFlags flags/*=0*/)
|
|
{
|
|
auto info = load<VkSemaphoreCreateInfo>(DATA, "draw");
|
|
info.flags = flags;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(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 vkinit::image_subresource_range(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 vkinit::semaphore_submit_info(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 vkinit::command_buffer_submit_info(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 vkinit::submit_info(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 vkinit::image_create_info(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;
|
|
|
|
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
info.usage = usageFlags;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkImageViewCreateInfo vkinit::imageview_create_info(VkFormat format, VkImage image, VkImageAspectFlags aspectFlags)
|
|
{
|
|
auto info = load<VkImageViewCreateInfo>(DATA, "draw");
|
|
|
|
info.image = image;
|
|
info.format = format;
|
|
info.subresourceRange.aspectMask = aspectFlags;
|
|
|
|
return info;
|
|
}
|
|
|
|
VkRenderingAttachmentInfo vkinit::attachment_info(
|
|
VkImageView view, VkClearValue* clear ,VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/)
|
|
{
|
|
VkRenderingAttachmentInfo colorAttachment {};
|
|
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
|
colorAttachment.pNext = nullptr;
|
|
|
|
colorAttachment.imageView = view;
|
|
colorAttachment.imageLayout = layout;
|
|
colorAttachment.loadOp = clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
|
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
|
|
if (clear) {
|
|
colorAttachment.clearValue = *clear;
|
|
}
|
|
|
|
return colorAttachment;
|
|
}
|
|
|
|
|
|
VkRenderingInfo vkinit::rendering_info(VkExtent2D renderExtent, VkRenderingAttachmentInfo* colorAttachment,
|
|
VkRenderingAttachmentInfo* depthAttachment)
|
|
{
|
|
VkRenderingInfo renderInfo {};
|
|
renderInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
|
renderInfo.pNext = nullptr;
|
|
|
|
renderInfo.renderArea = VkRect2D { VkOffset2D { 0, 0 }, renderExtent };
|
|
renderInfo.layerCount = 1;
|
|
renderInfo.colorAttachmentCount = 1;
|
|
renderInfo.pColorAttachments = colorAttachment;
|
|
renderInfo.pDepthAttachment = depthAttachment;
|
|
renderInfo.pStencilAttachment = nullptr;
|
|
|
|
return renderInfo;
|
|
}
|