コード例 #1
0
        public void CmdResetEvent(IMgEvent @event, MgPipelineStageFlagBits stageMask)
        {
            var bEvent = (VkEvent)@event;

            Debug.Assert(bEvent != null);

            Interops.vkCmdResetEvent(this.Handle, bEvent.Handle, (VkPipelineStageFlags)stageMask);
        }
コード例 #2
0
        public void CmdWriteTimestamp(MgPipelineStageFlagBits pipelineStage, IMgQueryPool queryPool, UInt32 query)
        {
            var bQueryPool = (VkQueryPool)queryPool;

            Debug.Assert(bQueryPool != null);

            Interops.vkCmdWriteTimestamp(this.Handle, (VkPipelineStageFlags)pipelineStage, bQueryPool.Handle, query);
        }
コード例 #3
0
        public void CmdPipelineBarrier(MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgDependencyFlagBits dependencyFlags, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
        {
            unsafe
            {
                var memBarrierCount = pMemoryBarriers != null ? (uint)pMemoryBarriers.Length : 0U;
                var pMemBarriers    = stackalloc VkMemoryBarrier[(int)memBarrierCount];

                for (var i = 0; i < memBarrierCount; ++i)
                {
                    pMemBarriers[i] = new VkMemoryBarrier
                    {
                        sType         = VkStructureType.StructureTypeMemoryBarrier,
                        pNext         = IntPtr.Zero,
                        srcAccessMask = (VkAccessFlags)pMemoryBarriers[i].SrcAccessMask,
                        dstAccessMask = (VkAccessFlags)pMemoryBarriers[i].DstAccessMask,
                    };
                }


                uint bufBarrierCount = pBufferMemoryBarriers != null ? (uint)pBufferMemoryBarriers.Length : 0U;
                var  pBufBarriers    = stackalloc VkBufferMemoryBarrier[(int)bufBarrierCount];
                for (var j = 0; j < bufBarrierCount; ++j)
                {
                    var current = pBufferMemoryBarriers[j];
                    var bBuffer = (VkBuffer)current.Buffer;
                    Debug.Assert(bBuffer != null);

                    pBufBarriers[j] = new VkBufferMemoryBarrier
                    {
                        sType               = VkStructureType.StructureTypeBufferMemoryBarrier,
                        pNext               = IntPtr.Zero,
                        dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                        srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                        srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                        dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                        buffer              = bBuffer.Handle,
                        offset              = current.Offset,
                        size = current.Size,
                    };
                }


                uint imgBarriersCount = pImageMemoryBarriers != null ? (uint)pImageMemoryBarriers.Length : 0U;
                var  pImgBarriers     = stackalloc VkImageMemoryBarrier[(int)imgBarriersCount];

                for (var k = 0; k < imgBarriersCount; ++k)
                {
                    var current = pImageMemoryBarriers[k];
                    var bImage  = (VkImage)current.Image;
                    Debug.Assert(bImage != null);

                    pImgBarriers[k] = new VkImageMemoryBarrier
                    {
                        sType               = VkStructureType.StructureTypeImageMemoryBarrier,
                        pNext               = IntPtr.Zero,
                        dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                        srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                        oldLayout           = (VkImageLayout)current.OldLayout,
                        newLayout           = (VkImageLayout)current.NewLayout,
                        srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                        dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                        image               = bImage.Handle,
                        subresourceRange    = new VkImageSubresourceRange
                        {
                            aspectMask     = (VkImageAspectFlags)current.SubresourceRange.AspectMask,
                            baseArrayLayer = current.SubresourceRange.BaseArrayLayer,
                            baseMipLevel   = current.SubresourceRange.BaseMipLevel,
                            layerCount     = current.SubresourceRange.LayerCount,
                            levelCount     = current.SubresourceRange.LevelCount,
                        }
                    };
                }

                VkMemoryBarrier *      mems   = memBarrierCount > 0 ? pMemBarriers : null;
                VkBufferMemoryBarrier *bufs   = bufBarrierCount > 0 ? pBufBarriers : null;
                VkImageMemoryBarrier * images = imgBarriersCount > 0 ? pImgBarriers : null;


                Interops.vkCmdPipelineBarrier(Handle,
                                              (VkPipelineStageFlags)srcStageMask,
                                              (VkPipelineStageFlags)dstStageMask,
                                              (VkDependencyFlags)dependencyFlags,
                                              memBarrierCount,
                                              mems,
                                              bufBarrierCount,
                                              bufs,
                                              imgBarriersCount,
                                              images);
            }
        }
コード例 #4
0
        public void CmdWaitEvents(IMgEvent[] pEvents, MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
        {
            unsafe
            {
                var eventHandles = stackalloc UInt64[pEvents.Length];
                var eventCount   = (uint)pEvents.Length;
                for (var i = 0; i < eventCount; ++i)
                {
                    var bEvent = (VkEvent)pEvents[i];
                    Debug.Assert(bEvent != null);
                    eventHandles[i] = bEvent.Handle;
                }

                var memBarrierCount           = 0U;
                VkMemoryBarrier *pMemBarriers = null;
                if (pMemoryBarriers != null)
                {
                    memBarrierCount = (uint)pMemoryBarriers.Length;
                    var tempMem = stackalloc VkMemoryBarrier[pMemoryBarriers.Length];
                    for (var i = 0; i < memBarrierCount; ++i)
                    {
                        tempMem[i] = new VkMemoryBarrier
                        {
                            sType         = VkStructureType.StructureTypeMemoryBarrier,
                            pNext         = IntPtr.Zero,
                            srcAccessMask = (VkAccessFlags)pMemoryBarriers[i].SrcAccessMask,
                            dstAccessMask = (VkAccessFlags)pMemoryBarriers[i].DstAccessMask,
                        };
                    }
                    pMemBarriers = tempMem;
                }

                uint bufBarrierCount = 0;
                VkBufferMemoryBarrier *pBufBarriers = null;
                if (pBufferMemoryBarriers != null)
                {
                    bufBarrierCount = (uint)pBufferMemoryBarriers.Length;
                    var tempBuf = stackalloc VkBufferMemoryBarrier[pBufferMemoryBarriers.Length];
                    for (var i = 0; i < bufBarrierCount; ++i)
                    {
                        var current = pBufferMemoryBarriers[i];
                        var bBuffer = (VkBuffer)current.Buffer;
                        Debug.Assert(bBuffer != null);

                        tempBuf[i] = new VkBufferMemoryBarrier
                        {
                            sType               = VkStructureType.StructureTypeBufferMemoryBarrier,
                            pNext               = IntPtr.Zero,
                            dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                            srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                            srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                            dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                            buffer              = bBuffer.Handle,
                            offset              = current.Offset,
                            size = current.Size,
                        };
                    }
                    pBufBarriers = tempBuf;
                }

                uint imgBarriersCount = 0;
                VkImageMemoryBarrier *pImgBarriers = null;

                if (pImageMemoryBarriers != null)
                {
                    imgBarriersCount = (uint)pImageMemoryBarriers.Length;
                    var tempImg = stackalloc VkImageMemoryBarrier[pImageMemoryBarriers.Length];
                    for (var i = 0; i < bufBarrierCount; ++i)
                    {
                        var current = pImageMemoryBarriers[i];
                        var bImage  = (VkImage)current.Image;
                        Debug.Assert(bImage != null);

                        tempImg[i] = new VkImageMemoryBarrier
                        {
                            sType               = VkStructureType.StructureTypeImageMemoryBarrier,
                            pNext               = IntPtr.Zero,
                            dstAccessMask       = (VkAccessFlags)current.DstAccessMask,
                            srcAccessMask       = (VkAccessFlags)current.SrcAccessMask,
                            oldLayout           = (Magnesium.Vulkan.VkImageLayout)current.OldLayout,
                            newLayout           = (Magnesium.Vulkan.VkImageLayout)current.NewLayout,
                            srcQueueFamilyIndex = current.SrcQueueFamilyIndex,
                            dstQueueFamilyIndex = current.DstQueueFamilyIndex,
                            image               = bImage.Handle,
                            subresourceRange    = new VkImageSubresourceRange
                            {
                                aspectMask     = (Magnesium.Vulkan.VkImageAspectFlags)current.SubresourceRange.AspectMask,
                                baseArrayLayer = current.SubresourceRange.BaseArrayLayer,
                                baseMipLevel   = current.SubresourceRange.BaseMipLevel,
                                layerCount     = current.SubresourceRange.LayerCount,
                                levelCount     = current.SubresourceRange.LevelCount,
                            }
                        };
                    }
                    pImgBarriers = tempImg;
                }

                Interops.vkCmdWaitEvents(
                    this.Handle,
                    eventCount,
                    eventHandles,
                    (VkPipelineStageFlags)srcStageMask,
                    (VkPipelineStageFlags)dstStageMask,
                    memBarrierCount,
                    pMemBarriers,
                    bufBarrierCount,
                    pBufBarriers,
                    imgBarriersCount,
                    pImgBarriers);
            }
        }
コード例 #5
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
        private void PushImageMemoryBarrier(
            IMgCommandBuffer cmdbuffer,
            IMgImage image,
            MgImageAspectFlagBits aspectMask,
            MgImageLayout oldImageLayout,
            MgImageLayout newImageLayout,
            MgImageSubresourceRange subresourceRange)
        {
            const uint VK_QUEUE_FAMILY_IGNORED = ~0U;            // 0xffffffff;

            // Create an image barrier object
            MgImageMemoryBarrier imageMemoryBarrier = new MgImageMemoryBarrier {
                OldLayout        = oldImageLayout,
                NewLayout        = newImageLayout,
                Image            = image,
                SubresourceRange = subresourceRange,
                // Some default values
                SrcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
                DstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
            };

            // Source layouts (old)

            // Undefined layout
            // Only allowed as initial layout!
            // Make sure any writes to the image have been finished
            if (oldImageLayout == MgImageLayout.PREINITIALIZED)
            {
                imageMemoryBarrier.SrcAccessMask = (MgAccessFlagBits.HOST_WRITE_BIT | MgAccessFlagBits.TRANSFER_WRITE_BIT);
            }

            // Old layout is color attachment
            // Make sure any writes to the color buffer have been finished
            if (oldImageLayout == MgImageLayout.COLOR_ATTACHMENT_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.COLOR_ATTACHMENT_WRITE_BIT;
            }

            // Old layout is depth/stencil attachment
            // Make sure any writes to the depth/stencil buffer have been finished
            if (oldImageLayout == MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
            }

            // Old layout is transfer source
            // Make sure any reads from the image have been finished
            if (oldImageLayout == MgImageLayout.TRANSFER_SRC_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.TRANSFER_READ_BIT;
            }

            // Old layout is shader read (sampler, input attachment)
            // Make sure any shader reads from the image have been finished
            if (oldImageLayout == MgImageLayout.SHADER_READ_ONLY_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.SHADER_READ_BIT;
            }

            // Target layouts (new)

            // New layout is transfer destination (copy, blit)
            // Make sure any copyies to the image have been finished
            if (newImageLayout == MgImageLayout.TRANSFER_DST_OPTIMAL)
            {
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.TRANSFER_WRITE_BIT;
            }

            // New layout is transfer source (copy, blit)
            // Make sure any reads from and writes to the image have been finished
            if (newImageLayout == MgImageLayout.TRANSFER_SRC_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = imageMemoryBarrier.SrcAccessMask | MgAccessFlagBits.TRANSFER_READ_BIT;
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.TRANSFER_READ_BIT;
            }

            // New layout is color attachment
            // Make sure any writes to the color buffer have been finished
            if (newImageLayout == MgImageLayout.COLOR_ATTACHMENT_OPTIMAL)
            {
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.COLOR_ATTACHMENT_WRITE_BIT;
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.TRANSFER_READ_BIT;
            }

            // New layout is depth attachment
            // Make sure any writes to depth/stencil buffer have been finished
            if (newImageLayout == MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
            {
                imageMemoryBarrier.DstAccessMask = imageMemoryBarrier.DstAccessMask | MgAccessFlagBits.DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
            }

            // New layout is shader read (sampler, input attachment)
            // Make sure any writes to the image have been finished
            if (newImageLayout == MgImageLayout.SHADER_READ_ONLY_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.HOST_WRITE_BIT | MgAccessFlagBits.TRANSFER_WRITE_BIT;
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.SHADER_READ_BIT;
            }

            // Put barrier on top
            MgPipelineStageFlagBits srcStageFlags  = MgPipelineStageFlagBits.TOP_OF_PIPE_BIT;
            MgPipelineStageFlagBits destStageFlags = MgPipelineStageFlagBits.TOP_OF_PIPE_BIT;

            // Put barrier inside setup command buffer
            cmdbuffer.CmdPipelineBarrier(
                srcStageFlags,
                destStageFlags,
                0,
                null,
                null,
                new [] { imageMemoryBarrier });
        }
コード例 #6
0
        // Create an image memory barrier for changing the layout of
        // an image and put it into an active command buffer
        public void SetImageLayout(
            IMgCommandBuffer cmdBuffer,
            IMgImage image,
            MgImageAspectFlagBits aspectMask,
            MgImageLayout oldImageLayout,
            MgImageLayout newImageLayout,
            uint mipLevel,
            uint mipLevelCount)
        {
            // Create an image barrier object
            var imageMemoryBarrier = new MgImageMemoryBarrier()
            {
                OldLayout        = oldImageLayout,
                NewLayout        = newImageLayout,
                Image            = image,
                SubresourceRange = new MgImageSubresourceRange {
                    AspectMask   = aspectMask,
                    BaseMipLevel = mipLevel,
                    LevelCount   = mipLevelCount,
                    LayerCount   = 1,
                },
            };

            // Only sets masks for layouts used in this example
            // For a more complete version that can be used with
            // other layouts see vkTools::setImageLayout

            // Source layouts (new)

            if (oldImageLayout == MgImageLayout.PREINITIALIZED)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.HOST_WRITE_BIT | MgAccessFlagBits.TRANSFER_WRITE_BIT;
            }

            // Target layouts (new)

            // New layout is transfer destination (copy, blit)
            // Make sure any reads from and writes to the image have been finished
            if (newImageLayout == MgImageLayout.TRANSFER_DST_OPTIMAL)
            {
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.TRANSFER_READ_BIT | MgAccessFlagBits.HOST_WRITE_BIT | MgAccessFlagBits.TRANSFER_WRITE_BIT;
            }

            // New layout is shader read (sampler, input attachment)
            // Make sure any writes to the image have been finished
            if (newImageLayout == MgImageLayout.SHADER_READ_ONLY_OPTIMAL)
            {
                imageMemoryBarrier.SrcAccessMask = MgAccessFlagBits.HOST_WRITE_BIT | MgAccessFlagBits.TRANSFER_WRITE_BIT;
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.SHADER_READ_BIT;
            }

            // New layout is transfer source (copy, blit)
            // Make sure any reads from and writes to the image have been finished
            if (newImageLayout == MgImageLayout.TRANSFER_SRC_OPTIMAL)
            {
                imageMemoryBarrier.DstAccessMask = MgAccessFlagBits.TRANSFER_READ_BIT | MgAccessFlagBits.HOST_WRITE_BIT | MgAccessFlagBits.TRANSFER_WRITE_BIT;
            }

            // Put barrier on top
            MgPipelineStageFlagBits srcStageFlags  = MgPipelineStageFlagBits.TOP_OF_PIPE_BIT;
            MgPipelineStageFlagBits destStageFlags = MgPipelineStageFlagBits.TOP_OF_PIPE_BIT;

            const int VK_FLAGS_NONE = 0;

            // Put barrier inside setup command buffer
            cmdBuffer.CmdPipelineBarrier(
                srcStageFlags,
                destStageFlags,
                VK_FLAGS_NONE,
                null,
                null,
                new [] { imageMemoryBarrier });
        }
コード例 #7
0
 public void CmdWriteTimestamp(MgPipelineStageFlagBits pipelineStage, IMgQueryPool queryPool, uint query)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
 public void CmdWaitEvents(IMgEvent[] pEvents, MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public void CmdSetEvent(IMgEvent @event, MgPipelineStageFlagBits stageMask)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 public void CmdPipelineBarrier(MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgDependencyFlagBits dependencyFlags, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
 public void CmdPipelineBarrier(MgPipelineStageFlagBits srcStageMask, MgPipelineStageFlagBits dstStageMask, MgDependencyFlagBits dependencyFlags, MgMemoryBarrier[] pMemoryBarriers, MgBufferMemoryBarrier[] pBufferMemoryBarriers, MgImageMemoryBarrier[] pImageMemoryBarriers)
 {
 }