Big cleanup to utilize C++20 designated initializers https://en.cppreference.com/w/cpp/language/aggregate_initialization.html#Designated_initializers
This commit is contained in:
parent
a996440c61
commit
d1d57ab682
4 changed files with 170 additions and 199 deletions
|
|
@ -3,10 +3,11 @@
|
||||||
void DescriptorLayoutBuilder::add_binding(uint32_t binding, VkDescriptorType type)
|
void DescriptorLayoutBuilder::add_binding(uint32_t binding, VkDescriptorType type)
|
||||||
{
|
{
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding newbind {};
|
VkDescriptorSetLayoutBinding newbind{
|
||||||
newbind.binding = binding;
|
.binding = binding,
|
||||||
newbind.descriptorCount = 1;
|
.descriptorType = type,
|
||||||
newbind.descriptorType = type;
|
.descriptorCount = 1,
|
||||||
|
};
|
||||||
|
|
||||||
bindings.push_back(newbind);
|
bindings.push_back(newbind);
|
||||||
}
|
}
|
||||||
|
|
@ -25,18 +26,16 @@ VkDescriptorSetLayout DescriptorLayoutBuilder::build(VkDevice device,
|
||||||
b.stageFlags |= shaderStages;
|
b.stageFlags |= shaderStages;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDescriptorSetLayoutCreateInfo info = {
|
VkDescriptorSetLayoutCreateInfo info{
|
||||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
|
.pNext = pNext,
|
||||||
|
.flags = flags,
|
||||||
|
.bindingCount = (uint32_t)bindings.size(),
|
||||||
|
.pBindings = bindings.data(),
|
||||||
};
|
};
|
||||||
info.pNext = pNext;
|
|
||||||
|
|
||||||
info.pBindings = bindings.data();
|
|
||||||
info.bindingCount = (uint32_t)bindings.size();
|
|
||||||
info.flags = flags;
|
|
||||||
|
|
||||||
VkDescriptorSetLayout set;
|
VkDescriptorSetLayout set;
|
||||||
VK_CHECK(vkCreateDescriptorSetLayout(device,
|
VK_CHECK(vkCreateDescriptorSetLayout(device, &info, nullptr, &set));
|
||||||
&info, nullptr, &set));
|
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
@ -46,19 +45,19 @@ void DescriptorAllocator::init_pool(VkDevice device, uint32_t maxSets,
|
||||||
{
|
{
|
||||||
std::vector<VkDescriptorPoolSize> poolSizes;
|
std::vector<VkDescriptorPoolSize> poolSizes;
|
||||||
for(PoolSizeRatio ratio : poolRatios) {
|
for(PoolSizeRatio ratio : poolRatios) {
|
||||||
poolSizes.push_back(VkDescriptorPoolSize{
|
poolSizes.push_back({
|
||||||
.type = ratio.type,
|
.type = ratio.type,
|
||||||
.descriptorCount = uint32_t(ratio.ratio * maxSets)
|
.descriptorCount = uint32_t(ratio.ratio * maxSets)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo pool_info = {
|
VkDescriptorPoolCreateInfo pool_info{
|
||||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||||
|
.flags = 0,
|
||||||
|
.maxSets = maxSets,
|
||||||
|
.poolSizeCount = (uint32_t)poolSizes.size(),
|
||||||
|
.pPoolSizes = poolSizes.data(),
|
||||||
};
|
};
|
||||||
pool_info.flags = 0;
|
|
||||||
pool_info.maxSets = maxSets;
|
|
||||||
pool_info.poolSizeCount = (uint32_t)poolSizes.size();
|
|
||||||
pool_info.pPoolSizes = poolSizes.data();
|
|
||||||
|
|
||||||
vkCreateDescriptorPool(device, &pool_info, nullptr, &pool);
|
vkCreateDescriptorPool(device, &pool_info, nullptr, &pool);
|
||||||
}
|
}
|
||||||
|
|
@ -75,15 +74,13 @@ void DescriptorAllocator::destroy_pool(VkDevice device)
|
||||||
|
|
||||||
VkDescriptorSet DescriptorAllocator::allocate(VkDevice device, VkDescriptorSetLayout layout)
|
VkDescriptorSet DescriptorAllocator::allocate(VkDevice device, VkDescriptorSetLayout layout)
|
||||||
{
|
{
|
||||||
VkDescriptorSetAllocateInfo allocInfo = {
|
VkDescriptorSetAllocateInfo allocInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
||||||
|
.descriptorPool = pool,
|
||||||
|
.descriptorSetCount = 1,
|
||||||
|
.pSetLayouts = &layout,
|
||||||
};
|
};
|
||||||
|
|
||||||
allocInfo.pNext = nullptr;
|
|
||||||
allocInfo.descriptorPool = pool;
|
|
||||||
allocInfo.descriptorSetCount = 1;
|
|
||||||
allocInfo.pSetLayouts = &layout;
|
|
||||||
|
|
||||||
VkDescriptorSet ds;
|
VkDescriptorSet ds;
|
||||||
VK_CHECK(vkAllocateDescriptorSets(device, &allocInfo, &ds));
|
VK_CHECK(vkAllocateDescriptorSets(device, &allocInfo, &ds));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,25 @@
|
||||||
|
|
||||||
void vkutil::transition_image(VkCommandBuffer cmd, VkImage image, VkImageLayout currentLayout, VkImageLayout newLayout)
|
void vkutil::transition_image(VkCommandBuffer cmd, VkImage image, VkImageLayout currentLayout, VkImageLayout newLayout)
|
||||||
{
|
{
|
||||||
VkImageMemoryBarrier2 imageBarrier{};
|
|
||||||
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;
|
|
||||||
|
|
||||||
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::image_subresource_range(aspectMask);
|
|
||||||
imageBarrier.image = image;
|
|
||||||
|
|
||||||
VkDependencyInfo depInfo{};
|
VkImageMemoryBarrier2 imageBarrier{
|
||||||
depInfo.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
||||||
depInfo.pNext = nullptr;
|
.srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
|
||||||
depInfo.imageMemoryBarrierCount = 1;
|
.srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT,
|
||||||
depInfo.pImageMemoryBarriers = &imageBarrier;
|
.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,
|
||||||
|
.image = image,
|
||||||
|
.subresourceRange = vkinit::image_subresource_range(aspectMask),
|
||||||
|
};
|
||||||
|
|
||||||
|
VkDependencyInfo depInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
|
||||||
|
.imageMemoryBarrierCount = 1,
|
||||||
|
.pImageMemoryBarriers = &imageBarrier,
|
||||||
|
};
|
||||||
|
|
||||||
vkCmdPipelineBarrier2(cmd, &depInfo);
|
vkCmdPipelineBarrier2(cmd, &depInfo);
|
||||||
}
|
}
|
||||||
|
|
@ -33,39 +30,45 @@ void vkutil::copy_image_to_image(VkCommandBuffer cmd, VkImage source, VkImage de
|
||||||
{
|
{
|
||||||
VkImageBlit2 blitRegion{
|
VkImageBlit2 blitRegion{
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_BLIT_2,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_BLIT_2,
|
||||||
.pNext = nullptr
|
|
||||||
};
|
};
|
||||||
|
|
||||||
blitRegion.srcOffsets[1].x = srcSize.width;
|
blitRegion.srcSubresource = {
|
||||||
blitRegion.srcOffsets[1].y = srcSize.height;
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
blitRegion.srcOffsets[1].z = 1;
|
.mipLevel = 0,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1,
|
||||||
|
};
|
||||||
|
|
||||||
blitRegion.dstOffsets[1].x = dstSize.width;
|
blitRegion.dstSubresource = {
|
||||||
blitRegion.dstOffsets[1].y = dstSize.height;
|
.aspectMask=VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
blitRegion.dstOffsets[1].z = 1;
|
.mipLevel=0,
|
||||||
|
.baseArrayLayer=0,
|
||||||
|
.layerCount=1,
|
||||||
|
};
|
||||||
|
|
||||||
blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
blitRegion.srcOffsets[1] = {
|
||||||
blitRegion.srcSubresource.baseArrayLayer = 0;
|
.x = int32_t(srcSize.width),
|
||||||
blitRegion.srcSubresource.layerCount = 1;
|
.y = int32_t(srcSize.height),
|
||||||
blitRegion.srcSubresource.mipLevel = 0;
|
.z = 1,
|
||||||
|
};
|
||||||
|
|
||||||
blitRegion.dstSubresource.aspectMask=VK_IMAGE_ASPECT_COLOR_BIT;
|
blitRegion.dstOffsets[1] = {
|
||||||
blitRegion.dstSubresource.baseArrayLayer=0;
|
.x = int32_t(dstSize.width),
|
||||||
blitRegion.dstSubresource.layerCount=1;
|
.y = int32_t(dstSize.height),
|
||||||
blitRegion.dstSubresource.mipLevel=0;
|
.z = 1,
|
||||||
|
};
|
||||||
|
|
||||||
VkBlitImageInfo2 blitInfo{
|
VkBlitImageInfo2 blitInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_BLIT_IMAGE_INFO_2, .pNext = nullptr
|
.sType = VK_STRUCTURE_TYPE_BLIT_IMAGE_INFO_2,
|
||||||
|
.srcImage = source,
|
||||||
|
.srcImageLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||||
|
.dstImage = destination,
|
||||||
|
.dstImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||||
|
.regionCount = 1,
|
||||||
|
.pRegions = &blitRegion,
|
||||||
|
.filter = VK_FILTER_LINEAR,
|
||||||
};
|
};
|
||||||
|
|
||||||
blitInfo.dstImage = destination;
|
|
||||||
blitInfo.dstImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
|
||||||
blitInfo.srcImage = source;
|
|
||||||
blitInfo.srcImageLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
|
||||||
blitInfo.filter = VK_FILTER_LINEAR;
|
|
||||||
blitInfo.regionCount = 1;
|
|
||||||
blitInfo.pRegions = &blitRegion;
|
|
||||||
|
|
||||||
vkCmdBlitImage2(cmd, &blitInfo);
|
vkCmdBlitImage2(cmd, &blitInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,163 +3,137 @@
|
||||||
VkCommandPoolCreateInfo vkinit::command_pool_create_info(uint32_t queueFamilyIndex,
|
VkCommandPoolCreateInfo vkinit::command_pool_create_info(uint32_t queueFamilyIndex,
|
||||||
VkCommandPoolCreateFlags flags /*= 0*/)
|
VkCommandPoolCreateFlags flags /*= 0*/)
|
||||||
{
|
{
|
||||||
VkCommandPoolCreateInfo info = {};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||||
info.pNext = nullptr;
|
.flags = flags,
|
||||||
info.queueFamilyIndex = queueFamilyIndex;
|
.queueFamilyIndex = queueFamilyIndex,
|
||||||
info.flags = flags;
|
};
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo vkinit::command_buffer_allocate_info(
|
VkCommandBufferAllocateInfo vkinit::command_buffer_allocate_info(
|
||||||
VkCommandPool pool, uint32_t count /*= 1*/)
|
VkCommandPool pool, uint32_t count /*= 1*/)
|
||||||
{
|
{
|
||||||
VkCommandBufferAllocateInfo info = {};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||||
info.pNext = nullptr;
|
.commandPool = pool,
|
||||||
|
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||||
info.commandPool = pool;
|
.commandBufferCount = count,
|
||||||
info.commandBufferCount = count;
|
};
|
||||||
info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkFenceCreateInfo vkinit::fence_create_info(VkFenceCreateFlags flags /*=0*/)
|
VkFenceCreateInfo vkinit::fence_create_info(VkFenceCreateFlags flags /*=0*/)
|
||||||
{
|
{
|
||||||
VkFenceCreateInfo info = {};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
||||||
info.pNext = nullptr;
|
.flags = flags
|
||||||
info.flags = flags;
|
};
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSemaphoreCreateInfo vkinit::semaphore_create_info(VkSemaphoreCreateFlags flags/*=0*/)
|
VkSemaphoreCreateInfo vkinit::semaphore_create_info(VkSemaphoreCreateFlags flags/*=0*/)
|
||||||
{
|
{
|
||||||
VkSemaphoreCreateInfo info = {};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||||
info.pNext = nullptr;
|
.flags = flags,
|
||||||
info.flags = flags;
|
};
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(VkCommandBufferUsageFlags flags /*= 0*/)
|
VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(VkCommandBufferUsageFlags flags /*= 0*/)
|
||||||
{
|
{
|
||||||
VkCommandBufferBeginInfo info = {};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||||
info.pNext = nullptr;
|
.flags = flags,
|
||||||
|
.pInheritanceInfo = nullptr,
|
||||||
info.pInheritanceInfo = nullptr;
|
};
|
||||||
info.flags = flags;
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImageSubresourceRange vkinit::image_subresource_range(VkImageAspectFlags aspectMask)
|
VkImageSubresourceRange vkinit::image_subresource_range(VkImageAspectFlags aspectMask)
|
||||||
{
|
{
|
||||||
VkImageSubresourceRange subImage {};
|
return {
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSemaphoreSubmitInfo vkinit::semaphore_submit_info(VkPipelineStageFlags2 stageMask, VkSemaphore semaphore)
|
VkSemaphoreSubmitInfo vkinit::semaphore_submit_info(VkPipelineStageFlags2 stageMask, VkSemaphore semaphore)
|
||||||
{
|
{
|
||||||
VkSemaphoreSubmitInfo submitInfo{};
|
return {
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;
|
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBufferSubmitInfo vkinit::command_buffer_submit_info(VkCommandBuffer cmd)
|
VkCommandBufferSubmitInfo vkinit::command_buffer_submit_info(VkCommandBuffer cmd)
|
||||||
{
|
{
|
||||||
VkCommandBufferSubmitInfo info{};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO,
|
||||||
info.pNext = nullptr;
|
.commandBuffer = cmd,
|
||||||
info.commandBuffer = cmd;
|
.deviceMask = 0,
|
||||||
info.deviceMask = 0;
|
};
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSubmitInfo2 vkinit::submit_info(VkCommandBufferSubmitInfo* cmd, VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
VkSubmitInfo2 vkinit::submit_info(VkCommandBufferSubmitInfo* cmd, VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
||||||
VkSemaphoreSubmitInfo* waitSemaphoreInfo)
|
VkSemaphoreSubmitInfo* waitSemaphoreInfo)
|
||||||
{
|
{
|
||||||
VkSubmitInfo2 info = {};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2;
|
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2,
|
||||||
info.pNext = nullptr;
|
.waitSemaphoreInfoCount = (waitSemaphoreInfo == nullptr ? 0u : 1u),
|
||||||
|
.pWaitSemaphoreInfos = waitSemaphoreInfo,
|
||||||
info.waitSemaphoreInfoCount = waitSemaphoreInfo == nullptr ? 0 : 1;
|
.commandBufferInfoCount = 1,
|
||||||
info.pWaitSemaphoreInfos = waitSemaphoreInfo;
|
.pCommandBufferInfos = cmd,
|
||||||
|
.signalSemaphoreInfoCount = (signalSemaphoreInfo == nullptr ? 0u : 1u),
|
||||||
info.signalSemaphoreInfoCount = signalSemaphoreInfo == nullptr ? 0 : 1;
|
.pSignalSemaphoreInfos = signalSemaphoreInfo,
|
||||||
info.pSignalSemaphoreInfos = signalSemaphoreInfo;
|
};
|
||||||
|
|
||||||
info.commandBufferInfoCount = 1;
|
|
||||||
info.pCommandBufferInfos = cmd;
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImageCreateInfo vkinit::image_create_info(VkFormat format, VkImageUsageFlags usageFlags, VkExtent3D extent)
|
VkImageCreateInfo vkinit::image_create_info(VkFormat format, VkImageUsageFlags usageFlags, VkExtent3D extent)
|
||||||
{
|
{
|
||||||
VkImageCreateInfo info{};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
||||||
info.pNext = nullptr;
|
.imageType = VK_IMAGE_TYPE_2D,
|
||||||
|
.format = format,
|
||||||
info.imageType = VK_IMAGE_TYPE_2D;
|
.extent = extent,
|
||||||
|
.mipLevels = 1,
|
||||||
info.format = format;
|
.arrayLayers = 1,
|
||||||
info.extent = extent;
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
|
.tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||||
info.mipLevels = 1;
|
.usage = usageFlags,
|
||||||
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)
|
VkImageViewCreateInfo vkinit::imageview_create_info(VkFormat format, VkImage image, VkImageAspectFlags aspectFlags)
|
||||||
{
|
{
|
||||||
VkImageViewCreateInfo info{};
|
return {
|
||||||
info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
info.pNext = nullptr;
|
.image = image,
|
||||||
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
||||||
info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
.format = format,
|
||||||
info.image = image;
|
.subresourceRange = {
|
||||||
info.format = format;
|
.aspectMask = aspectFlags,
|
||||||
info.subresourceRange.baseMipLevel = 0;
|
.baseMipLevel = 0,
|
||||||
info.subresourceRange.levelCount = 1;
|
.levelCount = 1,
|
||||||
info.subresourceRange.baseArrayLayer = 0;
|
.baseArrayLayer = 0,
|
||||||
info.subresourceRange.layerCount = 1;
|
.layerCount = 1,
|
||||||
info.subresourceRange.aspectMask = aspectFlags;
|
}
|
||||||
|
};
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkRenderingAttachmentInfo vkinit::attachment_info(
|
VkRenderingAttachmentInfo vkinit::attachment_info(
|
||||||
VkImageView view, VkClearValue* clear ,VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/)
|
VkImageView view, VkClearValue* clear ,VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/)
|
||||||
{
|
{
|
||||||
VkRenderingAttachmentInfo colorAttachment {};
|
VkRenderingAttachmentInfo colorAttachment{
|
||||||
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
|
||||||
colorAttachment.pNext = nullptr;
|
.imageView = view,
|
||||||
|
.imageLayout = layout,
|
||||||
colorAttachment.imageView = view;
|
.loadOp = clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD,
|
||||||
colorAttachment.imageLayout = layout;
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||||
colorAttachment.loadOp = clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
|
};
|
||||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
colorAttachment.clearValue = *clear;
|
colorAttachment.clearValue = *clear;
|
||||||
|
|
@ -172,16 +146,13 @@ VkRenderingAttachmentInfo vkinit::attachment_info(
|
||||||
VkRenderingInfo vkinit::rendering_info(VkExtent2D renderExtent, VkRenderingAttachmentInfo* colorAttachment,
|
VkRenderingInfo vkinit::rendering_info(VkExtent2D renderExtent, VkRenderingAttachmentInfo* colorAttachment,
|
||||||
VkRenderingAttachmentInfo* depthAttachment)
|
VkRenderingAttachmentInfo* depthAttachment)
|
||||||
{
|
{
|
||||||
VkRenderingInfo renderInfo {};
|
return {
|
||||||
renderInfo.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
|
||||||
renderInfo.pNext = nullptr;
|
.renderArea = VkRect2D { VkOffset2D { 0, 0 }, renderExtent },
|
||||||
|
.layerCount = 1,
|
||||||
renderInfo.renderArea = VkRect2D { VkOffset2D { 0, 0 }, renderExtent };
|
.colorAttachmentCount = 1,
|
||||||
renderInfo.layerCount = 1;
|
.pColorAttachments = colorAttachment,
|
||||||
renderInfo.colorAttachmentCount = 1;
|
.pDepthAttachment = depthAttachment,
|
||||||
renderInfo.pColorAttachments = colorAttachment;
|
.pStencilAttachment = nullptr,
|
||||||
renderInfo.pDepthAttachment = depthAttachment;
|
};
|
||||||
renderInfo.pStencilAttachment = nullptr;
|
|
||||||
|
|
||||||
return renderInfo;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ bool vkutil::load_shader_module(const char* filePath,
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
VkShaderModuleCreateInfo createInfo = {};
|
VkShaderModuleCreateInfo createInfo = {
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||||
createInfo.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
|
// codeSize has to be in bytes
|
||||||
// codeSize has to be in bytes
|
.codeSize = buffer.size() * sizeof(uint32_t),
|
||||||
createInfo.codeSize = buffer.size() * sizeof(uint32_t);
|
.pCode = buffer.data(),
|
||||||
createInfo.pCode = buffer.data();
|
};
|
||||||
|
|
||||||
VkShaderModule shaderModule;
|
VkShaderModule shaderModule;
|
||||||
if(vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
|
if(vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) != VK_SUCCESS) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue