コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }