Texture flickering with 2 dynamic rendering passes

I use 2 dynamic rendering passes:

// transition image to be used as color attachment
vkCmdBeginRendering()
 render clouds to texture (image is color attachment for this render pass)
vkCmdEndRendering();

// transition image to be used in shader
vkCmdBeginRendering()
 render screen space god rays (render full screen quad sampling the texture from the previous pass)
vkCmdEndRendering();

I get a lot of flickering. I would post a video, but it seems I cannot link videos here.

  • If I introduce a device wait till idle anywhere in the render loop, the flickering goes away
  • If instead I try to debug it using brute force barriers like so:
    static void fullBarrier(VkCommandBuffer commandBuffer)
    {
#if 0
        VkMemoryBarrier2 memoryBarrier = vkInitializers::memoryBarrier2();

        memoryBarrier.srcStageMask = memoryBarrier.dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;

        memoryBarrier.srcAccessMask = memoryBarrier.dstAccessMask =
            VK_ACCESS_2_MEMORY_READ_BIT | VK_ACCESS_2_MEMORY_WRITE_BIT
            | VK_ACCESS_2_INDEX_READ_BIT | VK_ACCESS_2_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_2_UNIFORM_READ_BIT | VK_ACCESS_2_INPUT_ATTACHMENT_READ_BIT
            | VK_ACCESS_2_SHADER_READ_BIT | VK_ACCESS_2_SHADER_WRITE_BIT
            | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT
            | VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
            | VK_ACCESS_2_TRANSFER_READ_BIT | VK_ACCESS_2_TRANSFER_WRITE_BIT
            | VK_ACCESS_2_HOST_READ_BIT | VK_ACCESS_2_HOST_WRITE_BIT
            | VK_ACCESS_2_SHADER_SAMPLED_READ_BIT | VK_ACCESS_2_SHADER_STORAGE_READ_BIT | VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT;

        VkDependencyInfo dependencyInfo = vkInitializers::dependencyInfo();
        dependencyInfo.memoryBarrierCount = 1;
        dependencyInfo.pMemoryBarriers = &memoryBarrier;
        vkCmdPipelineBarrier2(commandBuffer, &dependencyInfo);
#endif

        const VkPipelineStageFlags src_stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
        const VkPipelineStageFlags dst_stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
        const VkMemoryBarrier mem_barrier = {
            VK_STRUCTURE_TYPE_MEMORY_BARRIER,
            nullptr,
            VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
            VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
        };
        vkCmdPipelineBarrier(commandBuffer, src_stage, dst_stage, 0, 1, &mem_barrier, 0, nullptr, 0, nullptr);

    };

It does not seem to work.

One thing is that for my god rays shader I sample many locations. I read a few things in the spec and some forums, you can’t sample arbitrary location of any input attachment for subsequent render passes, but I am not sure whether I understand that right, or if it is applicable to this case (it is 2 separate rendering passes altogether)

Any input is useful. I have been struggling with this the last couple of days :confused:

Not much to say without seeing code.

Good practice is not to straight up barf caffeinated code from head, but occasionally oldschool get actual pen and paper and actually prove everything is synchronized correctly.

You can’t “sample” Input Attachment at all. Only thing you can do with it is fetch the “current”\local pixel value.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.