Compare commits
No commits in common. "d5d8dc50e4b03752ffcbd8f8e47638fc87483122" and "f05e1605d6d07f225cd924539eaa498c61705ccb" have entirely different histories.
d5d8dc50e4
...
f05e1605d6
@ -29,33 +29,35 @@ 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 {
|
VkImageMemoryBarrier2 imageBarrier {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2};
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
imageBarrier.pNext = nullptr;
|
||||||
.pNext = nullptr,
|
|
||||||
.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
|
imageBarrier.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
|
||||||
.srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT,
|
imageBarrier.srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT;
|
||||||
.dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
|
imageBarrier.dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
|
||||||
.dstAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT | VK_ACCESS_2_MEMORY_READ_BIT,
|
imageBarrier.dstAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT | VK_ACCESS_2_MEMORY_READ_BIT;
|
||||||
.oldLayout = currentLayout,
|
|
||||||
.newLayout = newLayout
|
imageBarrier.oldLayout = currentLayout;
|
||||||
};
|
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 {};
|
||||||
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
depInfo.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||||
.pNext = nullptr,
|
depInfo.pNext = nullptr;
|
||||||
.imageMemoryBarrierCount = 1,
|
|
||||||
.pImageMemoryBarriers = &imageBarrier
|
depInfo.imageMemoryBarrierCount = 1;
|
||||||
};
|
depInfo.pImageMemoryBarriers = &imageBarrier;
|
||||||
|
|
||||||
vkCmdPipelineBarrier2(cmd, &depInfo);
|
vkCmdPipelineBarrier2(cmd, &depInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,16 +79,18 @@ 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 = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
.flags = flags,
|
info.queueFamilyIndex = queueFamilyIndex;
|
||||||
.queueFamilyIndex = queueFamilyIndex
|
info.flags = flags;
|
||||||
};
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,24 +98,23 @@ namespace vkinit {
|
|||||||
VkCommandPool pool,
|
VkCommandPool pool,
|
||||||
uint32_t count
|
uint32_t count
|
||||||
) {
|
) {
|
||||||
VkCommandBufferAllocateInfo info {
|
VkCommandBufferAllocateInfo info = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
.commandPool = pool,
|
info.commandPool = pool;
|
||||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
info.commandBufferCount = count;
|
||||||
.commandBufferCount = count
|
info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
};
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkFenceCreateInfo fenceCreateInfo(
|
VkFenceCreateInfo fenceCreateInfo(
|
||||||
VkFenceCreateFlags flags /*= 0 */
|
VkFenceCreateFlags flags /*= 0 */
|
||||||
) {
|
) {
|
||||||
VkFenceCreateInfo info {
|
VkFenceCreateInfo info = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
.flags = flags
|
|
||||||
};
|
info.flags = flags;
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -121,11 +122,10 @@ namespace vkinit {
|
|||||||
VkSemaphoreCreateInfo semaphoreCreateInfo (
|
VkSemaphoreCreateInfo semaphoreCreateInfo (
|
||||||
VkSemaphoreCreateFlags flags /*= 0*/
|
VkSemaphoreCreateFlags flags /*= 0*/
|
||||||
) {
|
) {
|
||||||
VkSemaphoreCreateInfo info {
|
VkSemaphoreCreateInfo info = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
.flags = flags,
|
info.flags = flags;
|
||||||
};
|
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -133,28 +133,24 @@ namespace vkinit {
|
|||||||
VkCommandBufferBeginInfo commandBufferBeginInfo (
|
VkCommandBufferBeginInfo commandBufferBeginInfo (
|
||||||
VkCommandBufferUsageFlags flags /*= 0*/
|
VkCommandBufferUsageFlags flags /*= 0*/
|
||||||
) {
|
) {
|
||||||
VkCommandBufferBeginInfo info {
|
VkCommandBufferBeginInfo info = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
.pNext = nullptr,
|
info.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 {};
|
||||||
.aspectMask = aspectMask,
|
subImage.aspectMask = aspectMask;
|
||||||
.baseMipLevel = 0,
|
subImage.baseMipLevel = 0;
|
||||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
subImage.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||||
.baseArrayLayer = 0,
|
subImage.baseArrayLayer = 0;
|
||||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
subImage.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||||
};
|
|
||||||
|
|
||||||
return subImage;
|
return subImage;
|
||||||
}
|
}
|
||||||
@ -163,14 +159,13 @@ namespace vkinit {
|
|||||||
VkPipelineStageFlags2 stageMask,
|
VkPipelineStageFlags2 stageMask,
|
||||||
VkSemaphore semaphore
|
VkSemaphore semaphore
|
||||||
) {
|
) {
|
||||||
VkSemaphoreSubmitInfo submitInfo {
|
VkSemaphoreSubmitInfo submitInfo{};
|
||||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
|
submitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;
|
||||||
.pNext = nullptr,
|
submitInfo.pNext = nullptr;
|
||||||
.semaphore = semaphore,
|
submitInfo.semaphore = semaphore;
|
||||||
.value = 1,
|
submitInfo.stageMask = stageMask;
|
||||||
.stageMask = stageMask,
|
submitInfo.deviceIndex = 0;
|
||||||
.deviceIndex = 0
|
submitInfo.value = 1;
|
||||||
};
|
|
||||||
|
|
||||||
return submitInfo;
|
return submitInfo;
|
||||||
}
|
}
|
||||||
@ -178,12 +173,11 @@ namespace vkinit {
|
|||||||
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
|
VkCommandBufferSubmitInfo commandBufferSubmitInfo (
|
||||||
VkCommandBuffer cmd
|
VkCommandBuffer cmd
|
||||||
) {
|
) {
|
||||||
VkCommandBufferSubmitInfo info {
|
VkCommandBufferSubmitInfo info {};
|
||||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO,
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
.commandBuffer = cmd,
|
info.commandBuffer = cmd;
|
||||||
.deviceMask = 0
|
info.deviceMask = 0;
|
||||||
};
|
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -193,19 +187,18 @@ namespace vkinit {
|
|||||||
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
||||||
VkSemaphoreSubmitInfo* waitSemaphoreInfo
|
VkSemaphoreSubmitInfo* waitSemaphoreInfo
|
||||||
) {
|
) {
|
||||||
VkSubmitInfo2 info {
|
VkSubmitInfo2 info = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2,
|
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
|
|
||||||
.waitSemaphoreInfoCount = static_cast<uint32_t>(waitSemaphoreInfo == nullptr ? 0 : 1),
|
info.waitSemaphoreInfoCount = waitSemaphoreInfo == nullptr ? 0 : 1;
|
||||||
.pWaitSemaphoreInfos = waitSemaphoreInfo,
|
info.pWaitSemaphoreInfos = waitSemaphoreInfo;
|
||||||
|
|
||||||
.commandBufferInfoCount = 1,
|
info.signalSemaphoreInfoCount = signalSemaphoreInfo == nullptr ? 0 : 1;
|
||||||
.pCommandBufferInfos = cmd,
|
info.pSignalSemaphoreInfos = signalSemaphoreInfo;
|
||||||
|
|
||||||
.signalSemaphoreInfoCount = static_cast<uint32_t>(signalSemaphoreInfo == nullptr ? 0 : 1),
|
info.commandBufferInfoCount = 1;
|
||||||
.pSignalSemaphoreInfos = signalSemaphoreInfo
|
info.pCommandBufferInfos = cmd;
|
||||||
};
|
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -215,28 +208,30 @@ namespace vkinit {
|
|||||||
VkImageUsageFlags usageFlags,
|
VkImageUsageFlags usageFlags,
|
||||||
VkExtent3D extent
|
VkExtent3D extent
|
||||||
) {
|
) {
|
||||||
VkImageCreateInfo info = {
|
VkImageCreateInfo info = {};
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
.pNext = nullptr,
|
info.pNext = nullptr;
|
||||||
|
|
||||||
.imageType = VK_IMAGE_TYPE_2D,
|
info.imageType = VK_IMAGE_TYPE_2D;
|
||||||
|
|
||||||
.format = format,
|
info.format = format;
|
||||||
.extent = extent,
|
info.extent = extent;
|
||||||
|
|
||||||
.mipLevels = 1,
|
info.mipLevels = 1;
|
||||||
.arrayLayers = 1,
|
info.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
|
||||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
.tiling = VK_IMAGE_TILING_OPTIMAL,
|
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
.usage = usageFlags
|
info.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,
|
||||||
@ -303,6 +298,8 @@ namespace vkinit {
|
|||||||
};
|
};
|
||||||
return renderInfo;
|
return renderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user