Compare commits
2 Commits
f05e1605d6
...
d5d8dc50e4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5d8dc50e4 | ||
|
|
5308e0777b |
@ -29,35 +29,33 @@ namespace vkutil {
|
||||
#include "initializers.h"
|
||||
|
||||
namespace vkutil {
|
||||
// Todo :
|
||||
// Switch structs to designated initializers
|
||||
void transitionImage(
|
||||
VkCommandBuffer cmd,
|
||||
VkImage image,
|
||||
VkImageLayout currentLayout,
|
||||
VkImageLayout newLayout
|
||||
) {
|
||||
VkImageMemoryBarrier2 imageBarrier {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2};
|
||||
imageBarrier.pNext = nullptr;
|
||||
|
||||
imageBarrier.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
|
||||
imageBarrier.srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT;
|
||||
imageBarrier.dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
|
||||
imageBarrier.dstAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT | VK_ACCESS_2_MEMORY_READ_BIT;
|
||||
|
||||
imageBarrier.oldLayout = currentLayout;
|
||||
imageBarrier.newLayout = newLayout;
|
||||
VkImageMemoryBarrier2 imageBarrier {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
||||
.pNext = nullptr,
|
||||
.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
|
||||
.srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT,
|
||||
.dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
|
||||
.dstAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT | VK_ACCESS_2_MEMORY_READ_BIT,
|
||||
.oldLayout = currentLayout,
|
||||
.newLayout = newLayout
|
||||
};
|
||||
|
||||
VkImageAspectFlags aspectMask = (newLayout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
imageBarrier.subresourceRange = vkinit::imageSubresourceRange(aspectMask);
|
||||
imageBarrier.image = image;
|
||||
|
||||
VkDependencyInfo depInfo {};
|
||||
depInfo.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||
depInfo.pNext = nullptr;
|
||||
|
||||
depInfo.imageMemoryBarrierCount = 1;
|
||||
depInfo.pImageMemoryBarriers = &imageBarrier;
|
||||
VkDependencyInfo depInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
||||
.pNext = nullptr,
|
||||
.imageMemoryBarrierCount = 1,
|
||||
.pImageMemoryBarriers = &imageBarrier
|
||||
};
|
||||
|
||||
vkCmdPipelineBarrier2(cmd, &depInfo);
|
||||
}
|
||||
|
||||
@ -79,18 +79,16 @@ namespace vkinit {
|
||||
#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;
|
||||
VkCommandPoolCreateInfo info {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = flags,
|
||||
.queueFamilyIndex = queueFamilyIndex
|
||||
};
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -98,23 +96,24 @@ namespace vkinit {
|
||||
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;
|
||||
VkCommandBufferAllocateInfo info {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.commandPool = pool,
|
||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||
.commandBufferCount = count
|
||||
};
|
||||
return info;
|
||||
}
|
||||
|
||||
VkFenceCreateInfo fenceCreateInfo(
|
||||
VkFenceCreateFlags flags /*= 0 */
|
||||
) {
|
||||
VkFenceCreateInfo info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
|
||||
info.flags = flags;
|
||||
VkFenceCreateInfo info {
|
||||
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = flags
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
@ -122,10 +121,11 @@ namespace vkinit {
|
||||
VkSemaphoreCreateInfo semaphoreCreateInfo (
|
||||
VkSemaphoreCreateFlags flags /*= 0*/
|
||||
) {
|
||||
VkSemaphoreCreateInfo info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
info.flags = flags;
|
||||
VkSemaphoreCreateInfo info {
|
||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = flags,
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
@ -133,24 +133,28 @@ namespace vkinit {
|
||||
VkCommandBufferBeginInfo commandBufferBeginInfo (
|
||||
VkCommandBufferUsageFlags flags /*= 0*/
|
||||
) {
|
||||
VkCommandBufferBeginInfo info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
info.pNext = nullptr;
|
||||
VkCommandBufferBeginInfo info {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
.pNext = nullptr,
|
||||
|
||||
.flags = flags,
|
||||
.pInheritanceInfo = 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;
|
||||
VkImageSubresourceRange subImage {
|
||||
.aspectMask = aspectMask,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||
};
|
||||
|
||||
return subImage;
|
||||
}
|
||||
@ -159,13 +163,14 @@ namespace vkinit {
|
||||
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;
|
||||
VkSemaphoreSubmitInfo submitInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
|
||||
.pNext = nullptr,
|
||||
.semaphore = semaphore,
|
||||
.value = 1,
|
||||
.stageMask = stageMask,
|
||||
.deviceIndex = 0
|
||||
};
|
||||
|
||||
return submitInfo;
|
||||
}
|
||||
@ -173,11 +178,12 @@ namespace vkinit {
|
||||
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
|
||||
VkCommandBuffer cmd
|
||||
) {
|
||||
VkCommandBufferSubmitInfo info {};
|
||||
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
|
||||
info.pNext = nullptr;
|
||||
info.commandBuffer = cmd;
|
||||
info.deviceMask = 0;
|
||||
VkCommandBufferSubmitInfo info {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO,
|
||||
.pNext = nullptr,
|
||||
.commandBuffer = cmd,
|
||||
.deviceMask = 0
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
@ -187,18 +193,19 @@ namespace vkinit {
|
||||
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
||||
VkSemaphoreSubmitInfo* waitSemaphoreInfo
|
||||
) {
|
||||
VkSubmitInfo2 info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2;
|
||||
info.pNext = nullptr;
|
||||
VkSubmitInfo2 info {
|
||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2,
|
||||
.pNext = nullptr,
|
||||
|
||||
info.waitSemaphoreInfoCount = waitSemaphoreInfo == nullptr ? 0 : 1;
|
||||
info.pWaitSemaphoreInfos = waitSemaphoreInfo;
|
||||
.waitSemaphoreInfoCount = static_cast<uint32_t>(waitSemaphoreInfo == nullptr ? 0 : 1),
|
||||
.pWaitSemaphoreInfos = waitSemaphoreInfo,
|
||||
|
||||
info.signalSemaphoreInfoCount = signalSemaphoreInfo == nullptr ? 0 : 1;
|
||||
info.pSignalSemaphoreInfos = signalSemaphoreInfo;
|
||||
.commandBufferInfoCount = 1,
|
||||
.pCommandBufferInfos = cmd,
|
||||
|
||||
info.commandBufferInfoCount = 1;
|
||||
info.pCommandBufferInfos = cmd;
|
||||
.signalSemaphoreInfoCount = static_cast<uint32_t>(signalSemaphoreInfo == nullptr ? 0 : 1),
|
||||
.pSignalSemaphoreInfos = signalSemaphoreInfo
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
@ -208,30 +215,28 @@ namespace vkinit {
|
||||
VkImageUsageFlags usageFlags,
|
||||
VkExtent3D extent
|
||||
) {
|
||||
VkImageCreateInfo info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
VkImageCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
|
||||
info.imageType = VK_IMAGE_TYPE_2D;
|
||||
.imageType = VK_IMAGE_TYPE_2D,
|
||||
|
||||
info.format = format;
|
||||
info.extent = extent;
|
||||
.format = format,
|
||||
.extent = extent,
|
||||
|
||||
info.mipLevels = 1;
|
||||
info.arrayLayers = 1;
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 1,
|
||||
|
||||
//for MSAA. I won't be using it, so only 1 sample per pixel
|
||||
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
//for MSAA. I won't be using it, so only 1 sample per pixel
|
||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||
|
||||
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
info.usage = usageFlags;
|
||||
.tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = usageFlags
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
// Switched to designated initializers,
|
||||
// because it's more modern, and require less typing
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo(
|
||||
VkFormat format,
|
||||
VkImage image,
|
||||
@ -298,8 +303,6 @@ namespace vkinit {
|
||||
};
|
||||
return renderInfo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user