Turn vulkan_image_layout_transition_levels into macro

This commit is contained in:
twinaphex 2020-07-03 08:32:33 +02:00
parent 108dc26c86
commit 7a22eb1f44
3 changed files with 29 additions and 47 deletions

View File

@ -1335,37 +1335,6 @@ void vulkan_image_layout_transition(
1, &barrier);
}
void vulkan_image_layout_transition_levels(
VkCommandBuffer cmd, VkImage image, uint32_t levels,
VkImageLayout old_layout, VkImageLayout new_layout,
VkAccessFlags src_access, VkAccessFlags dst_access,
VkPipelineStageFlags src_stages, VkPipelineStageFlags dst_stages)
{
VkImageMemoryBarrier barrier;
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.pNext = NULL;
barrier.srcAccessMask = src_access;
barrier.dstAccessMask = dst_access;
barrier.oldLayout = old_layout;
barrier.newLayout = new_layout;
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.image = image;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barrier.subresourceRange.baseMipLevel = 0;
barrier.subresourceRange.levelCount = levels;
barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
vkCmdPipelineBarrier(cmd,
src_stages,
dst_stages,
false,
0, NULL,
0, NULL,
1, &barrier);
}
struct vk_buffer vulkan_create_buffer(
const struct vulkan_context *context,
size_t size, VkBufferUsageFlags usage)
@ -3686,7 +3655,7 @@ void vulkan_framebuffer_copy(VkImage image,
{
VkImageCopy region;
vulkan_image_layout_transition_levels(cmd, image,VK_REMAINING_MIP_LEVELS,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, image,VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
@ -3712,7 +3681,7 @@ void vulkan_framebuffer_copy(VkImage image,
image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, &region);
vulkan_image_layout_transition_levels(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
image,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
@ -3728,7 +3697,7 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
VkClearColorValue color;
VkImageSubresourceRange range;
vulkan_image_layout_transition_levels(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
image,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_UNDEFINED,
@ -3755,7 +3724,7 @@ void vulkan_framebuffer_clear(VkImage image, VkCommandBuffer cmd)
1,
&range);
vulkan_image_layout_transition_levels(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
image,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,

View File

@ -500,11 +500,24 @@ void vulkan_image_layout_transition(vk_t *vk,
VkAccessFlags srcAccess, VkAccessFlags dstAccess,
VkPipelineStageFlags srcStages, VkPipelineStageFlags dstStages);
void vulkan_image_layout_transition_levels(
VkCommandBuffer cmd, VkImage image, uint32_t levels,
VkImageLayout old_layout, VkImageLayout new_layout,
VkAccessFlags src_access, VkAccessFlags dst_access,
VkPipelineStageFlags src_stages, VkPipelineStageFlags dst_stages);
#define VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, img, levels, old_layout, new_layout, src_access, dst_access, src_stages, dst_stages) \
{ \
VkImageMemoryBarrier barrier; \
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; \
barrier.pNext = NULL; \
barrier.srcAccessMask = src_access; \
barrier.dstAccessMask = dst_access; \
barrier.oldLayout = old_layout; \
barrier.newLayout = new_layout; \
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; \
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; \
barrier.image = img; \
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; \
barrier.subresourceRange.baseMipLevel = 0; \
barrier.subresourceRange.levelCount = levels; \
barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; \
vkCmdPipelineBarrier(cmd, src_stages, dst_stages, false, 0, NULL, 0, NULL, 1, &barrier); \
}
static INLINE unsigned vulkan_format_to_bpp(VkFormat format)
{

View File

@ -622,7 +622,7 @@ static unique_ptr<StaticTexture> vulkan_filter_chain_load_lut(
memcpy(ptr, image.pixels, image.width * image.height * sizeof(uint32_t));
buffer->unmap();
vulkan_image_layout_transition_levels(cmd, tex,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd, tex,
VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_UNDEFINED,
shader->mipmap ? VK_IMAGE_LAYOUT_GENERAL
@ -677,7 +677,7 @@ static unique_ptr<StaticTexture> vulkan_filter_chain_load_lut(
/* Only injects execution and memory barriers,
* not actual transition. */
vulkan_image_layout_transition_levels(
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(
cmd,
tex,
VK_REMAINING_MIP_LEVELS,
@ -694,7 +694,7 @@ static unique_ptr<StaticTexture> vulkan_filter_chain_load_lut(
1, &blit_region, VK_FILTER_LINEAR);
}
vulkan_image_layout_transition_levels(
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(
cmd,
tex,
VK_REMAINING_MIP_LEVELS,
@ -965,7 +965,7 @@ void vulkan_filter_chain::update_history(DeferredDisposer &disposer,
/* Transition input texture to something appropriate. */
if (input_texture.layout != VK_IMAGE_LAYOUT_GENERAL)
{
vulkan_image_layout_transition_levels(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
input_texture.image,VK_REMAINING_MIP_LEVELS,
input_texture.layout,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
@ -992,7 +992,7 @@ void vulkan_filter_chain::update_history(DeferredDisposer &disposer,
/* Transition input texture back. */
if (input_texture.layout != VK_IMAGE_LAYOUT_GENERAL)
{
vulkan_image_layout_transition_levels(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
input_texture.image,VK_REMAINING_MIP_LEVELS,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
input_texture.layout,
@ -2252,7 +2252,7 @@ void Pass::build_commands(
VkRenderPassBeginInfo rp_info;
/* Render. */
vulkan_image_layout_transition_levels(cmd,
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(cmd,
framebuffer->get_image(), 1,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
@ -2346,7 +2346,7 @@ void Pass::build_commands(
else
{
/* Barrier to sync with next pass. */
vulkan_image_layout_transition_levels(
VULKAN_IMAGE_LAYOUT_TRANSITION_LEVELS(
cmd,
framebuffer->get_image(),
VK_REMAINING_MIP_LEVELS,