private VkImageMemoryBarrier.Buffer createPrePresentBarrier(long presentImage) { VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1) .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) .pNext(0) .srcAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT) .dstAccessMask(0) .oldLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .newLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED); imageMemoryBarrier.subresourceRange() .aspectMask(VK_IMAGE_ASPECT_COLOR_BIT) .baseMipLevel(0) .levelCount(1) .baseArrayLayer(0) .layerCount(1); imageMemoryBarrier.image(presentImage); return imageMemoryBarrier; }
private static VkImageMemoryBarrier.Buffer createPrePresentBarrier(long presentImage) { VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1) .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) .pNext(NULL) .srcAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT) .dstAccessMask(0) .oldLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .newLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED); imageMemoryBarrier.subresourceRange() .aspectMask(VK_IMAGE_ASPECT_COLOR_BIT) .baseMipLevel(0) .levelCount(1) .baseArrayLayer(0) .layerCount(1); imageMemoryBarrier.image(presentImage); return imageMemoryBarrier; }
private static VkImageMemoryBarrier.Buffer createPostPresentBarrier(long presentImage) { VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1) .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) .pNext(NULL) .srcAccessMask(0) .dstAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT) .oldLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) .newLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED); imageMemoryBarrier.subresourceRange() .aspectMask(VK_IMAGE_ASPECT_COLOR_BIT) .baseMipLevel(0) .levelCount(1) .baseArrayLayer(0) .layerCount(1); imageMemoryBarrier.image(presentImage); return imageMemoryBarrier; }
private static void imageBarrier(VkCommandBuffer cmdbuffer, long image, int aspectMask, int oldImageLayout, int srcAccess, int newImageLayout, int dstAccess) { // Create an image barrier object VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1) .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) .pNext(NULL) .oldLayout(oldImageLayout) .srcAccessMask(srcAccess) .newLayout(newImageLayout) .dstAccessMask(dstAccess) .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .image(image); imageMemoryBarrier.subresourceRange() .aspectMask(aspectMask) .baseMipLevel(0) .levelCount(1) .layerCount(1); // Put barrier on top int srcStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; int destStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // Put barrier inside setup command buffer vkCmdPipelineBarrier(cmdbuffer, srcStageFlags, destStageFlags, VK_FLAGS_NONE, null, // no memory barriers null, // no buffer memory barriers imageMemoryBarrier); // one image memory barrier imageMemoryBarrier.free(); }
private void createImageBarrier(VkCommandBuffer cmdbuffer, long image, int aspectMask, int oldImageLayout, int srcAccess, int newImageLayout, int dstAccess) { // Create an image barrier object VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1) .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) .pNext(0) .oldLayout(oldImageLayout) .srcAccessMask(srcAccess) .newLayout(newImageLayout) .dstAccessMask(dstAccess) .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .image(image); imageMemoryBarrier.subresourceRange() .aspectMask(aspectMask) .baseMipLevel(0) .levelCount(1) .layerCount(1); // Put barrier on top int srcStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; int destStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // Put barrier inside setup command buffer vkCmdPipelineBarrier(cmdbuffer, srcStageFlags, destStageFlags, 0, null, // no memory barriers null, // no buffer memory barriers imageMemoryBarrier); // one image memory barrier imageMemoryBarrier.free(); }
private static void submitPostPresentBarrier(long image, VkCommandBuffer commandBuffer, VkQueue queue) { VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.calloc() .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO) .pNext(NULL); int err = vkBeginCommandBuffer(commandBuffer, cmdBufInfo); cmdBufInfo.free(); if (err != VK_SUCCESS) { throw new AssertionError("Failed to begin command buffer: " + translateVulkanResult(err)); } VkImageMemoryBarrier.Buffer postPresentBarrier = createPostPresentBarrier(image); vkCmdPipelineBarrier( commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_FLAGS_NONE, null, // No memory barriers, null, // No buffer barriers, postPresentBarrier); // one image barrier postPresentBarrier.free(); err = vkEndCommandBuffer(commandBuffer); if (err != VK_SUCCESS) { throw new AssertionError("Failed to wait for idle queue: " + translateVulkanResult(err)); } // Submit the command buffer submitCommandBuffer(queue, commandBuffer); }
@UseNewStack private static void submitPostPresentBarrier(long image, VkCommandBuffer commandBuffer, VkQueue queue) { VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.callocStack() .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO) .pNext(NULL); int err = vkBeginCommandBuffer(commandBuffer, cmdBufInfo); if (err != VK_SUCCESS) { throw new AssertionError("Failed to begin command buffer: " + translateVulkanResult(err)); } VkImageMemoryBarrier.Buffer postPresentBarrier = VkImageMemoryBarrier.callocStack(1) .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) .pNext(NULL) .srcAccessMask(0) .dstAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT) .oldLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) .newLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED) .image(image); postPresentBarrier.subresourceRange() .aspectMask(VK_IMAGE_ASPECT_COLOR_BIT) .baseMipLevel(0) .levelCount(1) .baseArrayLayer(0) .layerCount(1); vkCmdPipelineBarrier( commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_FLAGS_NONE, null, // No memory barriers, null, // No buffer barriers, postPresentBarrier); // one image barrier err = vkEndCommandBuffer(commandBuffer); if (err != VK_SUCCESS) { throw new AssertionError("Failed to wait for idle queue: " + translateVulkanResult(err)); } // Submit the command buffer submitCommandBuffer(queue, commandBuffer); }