Exemple #1
0
 public void BindAndDispatch(CommandBuffer cmd, uint groupCountX, uint groupCountY = 1, uint groupCountZ = 1)
 {
     vkCmdBindPipeline(cmd.Handle, VkPipelineBindPoint.Compute, handle);
     vkCmdDispatch(cmd.Handle, groupCountX, groupCountY, groupCountZ);
 }
Exemple #2
0
 public override void BindDescriptorSet(CommandBuffer cmd, DescriptorSet dset, uint firstSet = 0)
 {
     cmd.BindDescriptorSet(VkPipelineBindPoint.Compute, layout, dset, firstSet);
 }
Exemple #3
0
        // Create an image memory barrier for changing the layout of
        // an image and put it into an active command buffer
        // See chapter 11.4 "Image Layout" for details
        public void SetLayout(
            CommandBuffer cmdbuffer,
            VkImageLayout oldImageLayout,
            VkImageLayout newImageLayout,
            VkImageSubresourceRange subresourceRange,
            VkPipelineStageFlags srcStageMask = VkPipelineStageFlags.AllCommands,
            VkPipelineStageFlags dstStageMask = VkPipelineStageFlags.AllCommands,
            uint srcQueueFamilyIndex          = Vk.QueueFamilyIgnored,
            uint dstQueueFamilyIndex          = Vk.QueueFamilyIgnored)
        {
            // Create an image barrier object
            VkImageMemoryBarrier imageMemoryBarrier = VkImageMemoryBarrier.New();

            imageMemoryBarrier.srcQueueFamilyIndex = srcQueueFamilyIndex;
            imageMemoryBarrier.dstQueueFamilyIndex = dstQueueFamilyIndex;
            imageMemoryBarrier.oldLayout           = oldImageLayout;
            imageMemoryBarrier.newLayout           = newImageLayout;
            imageMemoryBarrier.image            = handle;
            imageMemoryBarrier.subresourceRange = subresourceRange;

            // Source layouts (old)
            // Source access mask controls actions that have to be finished on the old layout
            // before it will be transitioned to the new layout
            switch (oldImageLayout)
            {
            case VkImageLayout.Undefined:
                // Image layout is undefined (or does not matter)
                // Only valid as initial layout
                // No flags required, listed only for completeness
                imageMemoryBarrier.srcAccessMask = 0;
                break;

            case VkImageLayout.Preinitialized:
                // Image is preinitialized
                // Only valid as initial layout for linear images, preserves memory contents
                // Make sure host writes have been finished
                imageMemoryBarrier.srcAccessMask = VkAccessFlags.HostWrite;
                break;

            case VkImageLayout.ColorAttachmentOptimal:
                // Image is a color attachment
                // Make sure any writes to the color buffer have been finished
                imageMemoryBarrier.srcAccessMask = VkAccessFlags.ColorAttachmentWrite;
                break;

            case VkImageLayout.DepthStencilAttachmentOptimal:
                // Image is a depth/stencil attachment
                // Make sure any writes to the depth/stencil buffer have been finished
                imageMemoryBarrier.srcAccessMask = VkAccessFlags.DepthStencilAttachmentWrite;
                break;

            case VkImageLayout.TransferSrcOptimal:
                // Image is a transfer source
                // Make sure any reads from the image have been finished
                imageMemoryBarrier.srcAccessMask = VkAccessFlags.TransferRead;
                break;

            case VkImageLayout.TransferDstOptimal:
                // Image is a transfer destination
                // Make sure any writes to the image have been finished
                imageMemoryBarrier.srcAccessMask = VkAccessFlags.TransferWrite;
                break;

            case VkImageLayout.ShaderReadOnlyOptimal:
                // Image is read by a shader
                // Make sure any shader reads from the image have been finished
                imageMemoryBarrier.srcAccessMask = VkAccessFlags.ShaderRead;
                break;
            }

            // Target layouts (new)
            // Destination access mask controls the dependency for the new image layout
            switch (newImageLayout)
            {
            case VkImageLayout.TransferDstOptimal:
                // Image will be used as a transfer destination
                // Make sure any writes to the image have been finished
                imageMemoryBarrier.dstAccessMask = VkAccessFlags.TransferWrite;
                break;

            case VkImageLayout.TransferSrcOptimal:
                // Image will be used as a transfer source
                // Make sure any reads from and writes to the image have been finished
                //imageMemoryBarrier.srcAccessMask |= VkAccessFlags.TransferRead;
                imageMemoryBarrier.dstAccessMask = VkAccessFlags.TransferRead;
                break;

            case VkImageLayout.ColorAttachmentOptimal:
                // Image will be used as a color attachment
                // Make sure any writes to the color buffer have been finished
                imageMemoryBarrier.srcAccessMask = oldImageLayout == VkImageLayout.ShaderReadOnlyOptimal ? VkAccessFlags.ShaderRead : VkAccessFlags.TransferRead;
                imageMemoryBarrier.dstAccessMask = VkAccessFlags.ColorAttachmentWrite;
                break;

            case VkImageLayout.DepthStencilAttachmentOptimal:
                // Image layout will be used as a depth/stencil attachment
                // Make sure any writes to depth/stencil buffer have been finished
                imageMemoryBarrier.dstAccessMask = imageMemoryBarrier.dstAccessMask | VkAccessFlags.DepthStencilAttachmentWrite;
                break;

            case VkImageLayout.ShaderReadOnlyOptimal:
                // Image will be read in a shader (sampler, input attachment)
                // Make sure any writes to the image have been finished
                if (imageMemoryBarrier.srcAccessMask == 0)
                {
                    imageMemoryBarrier.srcAccessMask = VkAccessFlags.HostWrite | VkAccessFlags.TransferWrite;
                }
                imageMemoryBarrier.dstAccessMask = VkAccessFlags.ShaderRead;
                break;
            }

            // Put barrier inside setup command buffer
            Vk.vkCmdPipelineBarrier(
                cmdbuffer.Handle,
                srcStageMask,
                dstStageMask,
                0,
                0, IntPtr.Zero,
                0, IntPtr.Zero,
                1, ref imageMemoryBarrier);

            lastKnownLayout = newImageLayout;
        }
Exemple #4
0
 public override void Bind(CommandBuffer cmd)
 {
     vkCmdBindPipeline(cmd.Handle, VkPipelineBindPoint.Compute, handle);
 }
Exemple #5
0
 public void SetLayout(CommandBuffer cmdbuffer,
                       VkImageAspectFlags aspectMask,
                       VkImageLayout newImageLayout)
 {
     SetLayout(cmdbuffer, aspectMask, lastKnownLayout, newImageLayout, lastKnownLayout.GetDefaultStage(), newImageLayout.GetDefaultStage());
 }