예제 #1
0
        protected ImageView CreateImageView(Image image, Format imageFormat)
        {
            var subresourceRange = new ImageSubresourceRange(ImageAspectFlags.Color, 0, 1, 0, 1);
            var createInfo       = new ImageViewCreateInfo(image, ImageViewType.ImageViewType2d, imageFormat, new ComponentMapping(), subresourceRange);

            return(device.CreateImageView(createInfo));
        }
예제 #2
0
        protected DeviceMemory BindImage(Image image)
        {
            var memRequirements = device.GetImageMemoryRequirements(image);
            var memTypeIndex    = FindMemoryIndex(MemoryPropertyFlags.DeviceLocal);
            var memAlloc        = new MemoryAllocateInfo(memRequirements.Size, memTypeIndex);
            var deviceMem       = device.AllocateMemory(memAlloc);

            device.BindImageMemory(image, deviceMem, 0);
            return(deviceMem);
        }
예제 #3
0
        protected void PipelineBarrierSetLayout(CommandBuffer cmdBuffer, Image image, ImageLayout oldLayout, ImageLayout newLayout, AccessFlags srcMask, AccessFlags dstMask)
        {
            var subresourceRange   = new ImageSubresourceRange(ImageAspectFlags.Color, 0, 1, 0, 1);
            var imageMemoryBarrier = new ImageMemoryBarrier(oldLayout, newLayout, 0, 0, image, subresourceRange);

            imageMemoryBarrier.SrcAccessMask = srcMask;
            imageMemoryBarrier.DstAccessMask = dstMask;
            var imageMemoryBarriers = new[] { imageMemoryBarrier };

            cmdBuffer.PipelineBarrier(PipelineStageFlags.TopOfPipe, PipelineStageFlags.TopOfPipe, DependencyFlags.None, null, null, imageMemoryBarriers);
            imageMemoryBarrier.Dispose();
        }
예제 #4
0
        public static Vk.ImageView CreateImageView(VkContext state, Vk.Image image, Vk.Format format,
                                                   Vk.ImageAspectFlags aspectFlags)
        {
            var subresourceRange = new Vk.ImageSubresourceRange();

            subresourceRange.AspectMask     = aspectFlags;
            subresourceRange.BaseMipLevel   = 0;
            subresourceRange.LevelCount     = 1;
            subresourceRange.BaseArrayLayer = 0;
            subresourceRange.LayerCount     = 1;

            var viewInfo = new Vk.ImageViewCreateInfo();

            viewInfo.Image            = image;
            viewInfo.ViewType         = Vk.ImageViewType.View2D;
            viewInfo.Format           = format;
            viewInfo.SubresourceRange = subresourceRange;

            return(state.Device.CreateImageView(viewInfo));
        }
예제 #5
0
        public void TransitionImageLayout(Vk.Image image, Vk.Format format,
                                          Vk.ImageLayout oldLayout, Vk.ImageLayout newLayout)
        {
            var buffer = this.BeginSingleTimeCommands(this.GraphicsCommandPool);

            var subresourceRange = new Vk.ImageSubresourceRange();

            if (newLayout == Vk.ImageLayout.DepthStencilAttachmentOptimal)
            {
                subresourceRange.AspectMask = Vk.ImageAspectFlags.Depth;

                if (VkHelper.HasStencilComponent(format))
                {
                    subresourceRange.AspectMask |= Vk.ImageAspectFlags.Stencil;
                }
            }
            else
            {
                subresourceRange.AspectMask = Vk.ImageAspectFlags.Color;
            }

            subresourceRange.BaseMipLevel   = 0;
            subresourceRange.LevelCount     = 1;
            subresourceRange.BaseArrayLayer = 0;
            subresourceRange.LayerCount     = 1;

            Vk.PipelineStageFlags srcStage;
            Vk.PipelineStageFlags dstStage;

            var barrier = new Vk.ImageMemoryBarrier();

            barrier.OldLayout           = oldLayout;
            barrier.NewLayout           = newLayout;
            barrier.SrcQueueFamilyIndex = VkConstants.VK_QUEUE_FAMILY_IGNORED;
            barrier.DstQueueFamilyIndex = VkConstants.VK_QUEUE_FAMILY_IGNORED;

            if (oldLayout == Vk.ImageLayout.Undefined && newLayout == Vk.ImageLayout.TransferDstOptimal)
            {
                barrier.SrcAccessMask = 0;
                barrier.DstAccessMask = Vk.AccessFlags.TransferWrite;

                srcStage = Vk.PipelineStageFlags.TopOfPipe;
                dstStage = Vk.PipelineStageFlags.Transfer;
            }
            else if (oldLayout == Vk.ImageLayout.TransferDstOptimal && newLayout == Vk.ImageLayout.ShaderReadOnlyOptimal)
            {
                barrier.SrcAccessMask = Vk.AccessFlags.TransferWrite;
                barrier.DstAccessMask = Vk.AccessFlags.ShaderRead;

                srcStage = Vk.PipelineStageFlags.Transfer;
                dstStage = Vk.PipelineStageFlags.FragmentShader;
            }
            else if (oldLayout == Vk.ImageLayout.Undefined && newLayout == Vk.ImageLayout.DepthStencilAttachmentOptimal)
            {
                barrier.SrcAccessMask = 0;
                barrier.DstAccessMask = Vk.AccessFlags.DepthStencilAttachmentRead
                                        | Vk.AccessFlags.DepthStencilAttachmentWrite;

                srcStage = Vk.PipelineStageFlags.TopOfPipe;
                dstStage = Vk.PipelineStageFlags.EarlyFragmentTests;
            }
            else
            {
                throw new Exception("Unsupported layout transition.");
            }

            barrier.Image            = image;
            barrier.SubresourceRange = subresourceRange;

            buffer.CmdPipelineBarrier(srcStage, dstStage, 0, null, null,
                                      new Vk.ImageMemoryBarrier[] { barrier });

            this.EndSingleTimeCommands(this.GraphicsQueue, this.GraphicsCommandPool, buffer);
        }