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