public ImageSubresourceLayers(ImageAspectFlags aspectMask, uint baseArrayLayer, uint layerCount, uint mipLevel)
 {
     AspectMask = aspectMask;
     BaseArrayLayer = baseArrayLayer;
     LayerCount = layerCount;
     MipLevel = mipLevel;
 }
 /// <summary>
 ///
 /// </summary>
 public ImageSubresourceLayers(ImageAspectFlags aspectMask, uint mipLevel, uint baseArrayLayer, uint layerCount)
 {
     this.AspectMask     = aspectMask;
     this.MipLevel       = mipLevel;
     this.BaseArrayLayer = baseArrayLayer;
     this.LayerCount     = layerCount;
 }
 public ImageSubresourceLayers(ImageAspectFlags aspectMask, uint baseArrayLayer, uint layerCount, uint mipLevel)
 {
     AspectMask     = aspectMask;
     BaseArrayLayer = baseArrayLayer;
     LayerCount     = layerCount;
     MipLevel       = mipLevel;
 }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 public ImageSubresourceRange(ImageAspectFlags aspectMask, uint baseMipLevel, uint levelCount, uint baseArrayLayer, uint layerCount)
 {
     this.AspectMask     = aspectMask;
     this.BaseMipLevel   = baseMipLevel;
     this.LevelCount     = levelCount;
     this.BaseArrayLayer = baseArrayLayer;
     this.LayerCount     = layerCount;
 }
 public ImageSubresourceRange(ImageAspectFlags aspectMask, uint baseArrayLayer, uint layerCount, uint baseMipLevel, uint levelCount)
 {
     AspectMask = aspectMask;
     BaseArrayLayer = baseArrayLayer;
     BaseMipLevel = baseMipLevel;
     LayerCount = layerCount;
     LevelCount = levelCount;
 }
 public ImagePlaneMemoryRequirementsInfo
 (
     StructureType sType          = StructureType.ImagePlaneMemoryRequirementsInfo,
     void *pNext                  = default,
     ImageAspectFlags planeAspect = default
 )
 {
     SType       = sType;
     PNext       = pNext;
     PlaneAspect = planeAspect;
 }
Example #7
0
 public ClearAttachment
 (
     ImageAspectFlags aspectMask = default,
     uint colorAttachment        = default,
     ClearValue clearValue       = default
 )
 {
     AspectMask      = aspectMask;
     ColorAttachment = colorAttachment;
     ClearValue      = clearValue;
 }
 public InputAttachmentAspectReferenceKHR
 (
     uint subpass = default,
     uint inputAttachmentIndex   = default,
     ImageAspectFlags aspectMask = default
 )
 {
     Subpass = subpass;
     InputAttachmentIndex = inputAttachmentIndex;
     AspectMask           = aspectMask;
 }
Example #9
0
 public ImageSubresource
 (
     ImageAspectFlags aspectMask = default,
     uint mipLevel   = default,
     uint arrayLayer = default
 )
 {
     AspectMask = aspectMask;
     MipLevel   = mipLevel;
     ArrayLayer = arrayLayer;
 }
 public BindImagePlaneMemoryInfoKHR
 (
     StructureType sType          = StructureType.BindImagePlaneMemoryInfo,
     void *pNext                  = default,
     ImageAspectFlags planeAspect = default
 )
 {
     SType       = sType;
     PNext       = pNext;
     PlaneAspect = planeAspect;
 }
Example #11
0
 public SparseImageFormatProperties
 (
     ImageAspectFlags aspectMask  = default,
     Extent3D imageGranularity    = default,
     SparseImageFormatFlags flags = default
 )
 {
     AspectMask       = aspectMask;
     ImageGranularity = imageGranularity;
     Flags            = flags;
 }
Example #12
0
 private ImageView CreateImageView(Image image, Format format, ImageAspectFlags aspectFlags)
 {
     return(device.CreateImageView(image, ImageViewType.ImageView2d, format, ComponentMapping.Identity,
                                   new ImageSubresourceRange
     {
         AspectMask = aspectFlags,
         BaseMipLevel = 0,
         LevelCount = 1,
         BaseArrayLayer = 0,
         LayerCount = 1
     }));
 }
 public ImageSubresourceLayers
 (
     ImageAspectFlags aspectMask = default,
     uint mipLevel       = default,
     uint baseArrayLayer = default,
     uint layerCount     = default
 )
 {
     AspectMask     = aspectMask;
     MipLevel       = mipLevel;
     BaseArrayLayer = baseArrayLayer;
     LayerCount     = layerCount;
 }
Example #14
0
        public static ImageWithMemory CreateSampledImageWithMemory(
            uint width,
            uint height,
            ImageUsageFlags imageUsageFlags,
            SampleCountFlags samples,
            Format format,
            ImageAspectFlags imageAspectFlags)
        {
            ImageWithMemory imageWithMemory = new ImageWithMemory
            {
                Image = VContext.Instance.device.CreateImage
                        (
                    new ImageCreateInfo()
                {
                    ImageType = ImageType.Image2D,
                    Format    = format,
                    Extent    = new Extent3D()
                    {
                        Width  = width,
                        Height = height,
                        Depth  = 1
                    },
                    MipLevels     = 1,
                    ArrayLayers   = 1,
                    Samples       = samples,
                    Tiling        = ImageTiling.Optimal,
                    Usage         = imageUsageFlags,
                    SharingMode   = SharingMode.Exclusive,
                    InitialLayout = ImageLayout.Undefined
                }
                        )
            };

            MemoryRequirements textureMemoryRequirements = VContext.Instance.device.GetImageMemoryRequirements(imageWithMemory.Image);
            uint memoryTypeIndex = Util.GetMemoryTypeIndex(textureMemoryRequirements.MemoryTypeBits, MemoryPropertyFlags.DeviceLocal);

            imageWithMemory.Memory = VContext.Instance.device.AllocateMemory
                                     (
                new MemoryAllocateInfo()
            {
                AllocationSize  = textureMemoryRequirements.Size,
                MemoryTypeIndex = memoryTypeIndex
            }
                                     );
            VContext.Instance.device.BindImageMemory(imageWithMemory.Image, imageWithMemory.Memory, 0);

            imageWithMemory.ImageView = VContext.Instance.CreateImageView(imageWithMemory.Image, format, imageAspectFlags);

            return(imageWithMemory);
        }
 public AttachmentReference2KHR
 (
     StructureType sType         = StructureType.AttachmentReference2,
     void *pNext                 = default,
     uint attachment             = default,
     ImageLayout layout          = default,
     ImageAspectFlags aspectMask = default
 )
 {
     SType      = sType;
     PNext      = pNext;
     Attachment = attachment;
     Layout     = layout;
     AspectMask = aspectMask;
 }
 public ImageSubresourceRange
 (
     ImageAspectFlags aspectMask = default,
     uint baseMipLevel           = default,
     uint levelCount             = default,
     uint baseArrayLayer         = default,
     uint layerCount             = default
 )
 {
     AspectMask     = aspectMask;
     BaseMipLevel   = baseMipLevel;
     LevelCount     = levelCount;
     BaseArrayLayer = baseArrayLayer;
     LayerCount     = layerCount;
 }
Example #17
0
        void SetImageLayout(Image image, ImageAspectFlags aspectMask, ImageLayout oldImageLayout, ImageLayout newImageLayout, AccessFlags srcAccessMask)
        {
            if (cmdSetup == null)
            {
                cmdSetup = CreateCommandBuffer(QueueFlags.Graphics);
                cmdSetup.Begin(new CommandBufferBeginInfo());
            }

            ImageMemoryBarrier imageMemoryBarrier = new ImageMemoryBarrier
            {
                SrcAccessMask    = (uint)srcAccessMask,
                DstAccessMask    = 0,
                OldLayout        = oldImageLayout,
                NewLayout        = newImageLayout,
                Image            = image,
                SubresourceRange = new ImageSubresourceRange
                {
                    AspectMask     = (uint)aspectMask,
                    BaseMipLevel   = 0,
                    LevelCount     = 1,
                    BaseArrayLayer = 0,
                    LayerCount     = 1,
                },
            };

            if (newImageLayout == ImageLayout.TransferDstOptimal)
            {
                imageMemoryBarrier.DstAccessMask = (uint)AccessFlags.TransferRead;
            }
            else if (newImageLayout == ImageLayout.ColorAttachmentOptimal)
            {
                imageMemoryBarrier.DstAccessMask = (uint)AccessFlags.ColorAttachmentWrite;
            }
            else if (newImageLayout == ImageLayout.DepthStencilAttachmentOptimal)
            {
                imageMemoryBarrier.DstAccessMask = (uint)AccessFlags.DepthStencilAttachmentWrite;
            }
            else if (newImageLayout == ImageLayout.ShaderReadOnlyOptimal)
            {
                imageMemoryBarrier.DstAccessMask = (uint)(AccessFlags.ShaderRead | AccessFlags.InputAttachmentRead);
            }

            // TODO Vulkan : we cant set null as this null->m will be called
            //cmdSetup.CmdPipelineBarrier(PipelineStageFlags.TopOfPipe, PipelineStageFlags.TopOfPipe, 0, 0, MemoryBarrier.Null, 0, BufferMemoryBarrier.Null, 1, imageMemoryBarrier);
            cmdSetup.CmdPipelineBarrier(PipelineStageFlags.TopOfPipe, PipelineStageFlags.TopOfPipe, 0, null, null, new ImageMemoryBarrier[] { imageMemoryBarrier });
        }
Example #18
0
 private ImageView CreateImageView(Image image, Format format, ImageAspectFlags aspectFlags)
 {
     return(device.CreateImageView(new ImageViewCreateInfo
     {
         Components = ComponentMapping.Identity,
         Format = format,
         Image = image,
         Flags = ImageViewCreateFlags.None,
         ViewType = ImageViewType.ImageView2d,
         SubresourceRange = new ImageSubresourceRange
         {
             AspectMask = aspectFlags,
             BaseMipLevel = 0,
             LevelCount = 1,
             BaseArrayLayer = 0,
             LayerCount = 1
         }
     }));
 }
Example #19
0
 public static void Blit(
     Vk api,
     CommandBuffer commandBuffer,
     Image srcImage,
     Image dstImage,
     TextureCreateInfo srcInfo,
     TextureCreateInfo dstInfo,
     Extents2D srcRegion,
     Extents2D dstRegion,
     int srcLayer,
     int dstLayer,
     int srcLevel,
     int dstLevel,
     int layers,
     int levels,
     bool linearFilter,
     ImageAspectFlags srcAspectFlags = 0,
     ImageAspectFlags dstAspectFlags = 0)
 {
Example #20
0
		protected void SetImageLayout(CommandBuffer commandBuffer, Image image, ImageAspectFlags aspectFlags, ImageLayout oldLayout, ImageLayout newLayout) {
			var imageMemoryBarrier = new ImageMemoryBarrier {
				OldLayout = oldLayout,
				NewLayout = newLayout,
				Image = image,
				SubresourceRange = new ImageSubresourceRange {
					AspectMask = aspectFlags,
					BaseMipLevel = 0,
					LevelCount = 1,
					LayerCount = 1,
					BaseArrayLayer = 0
				}
			};
			SetOptimalAccessMasks(imageMemoryBarrier, oldLayout, newLayout);
			commandBuffer.CmdPipelineBarrier(PipelineStageFlags.TopOfPipe,
			                                 PipelineStageFlags.TopOfPipe,
			                                 0,
			                                 0, null,
			                                 0, null,
			                                 1, imageMemoryBarrier);
		}
Example #21
0
        public static unsafe void InsertImageBarrier(
            Vk api,
            CommandBuffer commandBuffer,
            Image image,
            AccessFlags srcAccessMask,
            AccessFlags dstAccessMask,
            PipelineStageFlags srcStageMask,
            PipelineStageFlags dstStageMask,
            ImageAspectFlags aspectFlags,
            int firstLayer,
            int firstLevel,
            int layers,
            int levels)
        {
            ImageMemoryBarrier memoryBarrier = new ImageMemoryBarrier()
            {
                SType               = StructureType.ImageMemoryBarrier,
                SrcAccessMask       = srcAccessMask,
                DstAccessMask       = dstAccessMask,
                SrcQueueFamilyIndex = Vk.QueueFamilyIgnored,
                DstQueueFamilyIndex = Vk.QueueFamilyIgnored,
                Image               = image,
                OldLayout           = ImageLayout.General,
                NewLayout           = ImageLayout.General,
                SubresourceRange    = new ImageSubresourceRange(aspectFlags, (uint)firstLevel, (uint)levels, (uint)firstLayer, (uint)layers)
            };

            api.CmdPipelineBarrier(
                commandBuffer,
                srcStageMask,
                dstStageMask,
                0,
                0,
                null,
                0,
                null,
                1,
                memoryBarrier);
        }
Example #22
0
 public ImageSubresource(ImageAspectFlags aspectMask, uint arrayLayer, uint mipLevel)
 {
     AspectMask = aspectMask;
     MipLevel = mipLevel;
     ArrayLayer = arrayLayer;
 }
 public ImageSubresourceRange(ImageAspectFlags aspectMask)
     : this(aspectMask, 0, Vulkan.RemainingArrayLayers, 0, Vulkan.RemainingMipLevels)
 {
 }
Example #24
0
 /// <summary>
 ///
 /// </summary>
 public SparseImageFormatProperties(ImageAspectFlags aspectMask, Extent3D imageGranularity, SparseImageFormatFlags flags)
 {
     this.AspectMask       = aspectMask;
     this.ImageGranularity = imageGranularity;
     this.Flags            = flags;
 }
Example #25
0
 /// <summary>
 ///
 /// </summary>
 public ImageSubresource(ImageAspectFlags aspectMask, uint mipLevel, uint arrayLayer)
 {
     this.AspectMask = aspectMask;
     this.MipLevel   = mipLevel;
     this.ArrayLayer = arrayLayer;
 }
Example #26
0
        private void SetImageLayout(Image image, ImageAspectFlags imageAspect, ImageLayout oldLayout, ImageLayout newLayout)
        {
            if (setupCommanBuffer == CommandBuffer.Null)
            {
                // Create command buffer
                CommandBuffer setupCommandBuffer;
                var allocateInfo = new CommandBufferAllocateInfo
                {
                    StructureType = StructureType.CommandBufferAllocateInfo,
                    CommandPool = commandPool,
                    Level = CommandBufferLevel.Primary,
                    CommandBufferCount = 1,
                };
                device.AllocateCommandBuffers(ref allocateInfo, &setupCommandBuffer);
                setupCommanBuffer = setupCommandBuffer;

                // Begin command buffer
                var inheritanceInfo = new CommandBufferInheritanceInfo { StructureType = StructureType.CommandBufferInheritanceInfo };
                var beginInfo = new CommandBufferBeginInfo
                {
                    StructureType = StructureType.CommandBufferBeginInfo,
                    InheritanceInfo = new IntPtr(&inheritanceInfo)
                };
                setupCommanBuffer.Begin(ref beginInfo);
            }

            var imageMemoryBarrier = new ImageMemoryBarrier
            {
                StructureType = StructureType.ImageMemoryBarrier,
                OldLayout = oldLayout,
                NewLayout = newLayout,
                Image = image,
                SubresourceRange = new ImageSubresourceRange(imageAspect, 0, 1, 0, 1)
            };

            switch (newLayout)
            {
                case ImageLayout.TransferDestinationOptimal:
                    imageMemoryBarrier.DestinationAccessMask = AccessFlags.TransferRead;
                    break;
                case ImageLayout.ColorAttachmentOptimal:
                    imageMemoryBarrier.DestinationAccessMask = AccessFlags.ColorAttachmentWrite;
                    break;
                case ImageLayout.DepthStencilAttachmentOptimal:
                    imageMemoryBarrier.DestinationAccessMask = AccessFlags.DepthStencilAttachmentWrite;
                    break;
                case ImageLayout.ShaderReadOnlyOptimal:
                    imageMemoryBarrier.DestinationAccessMask = AccessFlags.ShaderRead | AccessFlags.InputAttachmentRead;
                    break;
            }

            var sourceStages = PipelineStageFlags.TopOfPipe;
            var destinationStages = PipelineStageFlags.TopOfPipe;

            setupCommanBuffer.PipelineBarrier(sourceStages, destinationStages, DependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier);
        }
Example #27
0
        private void SetImageLayout(Image image, ImageAspectFlags imageAspect, ImageLayout oldLayout, ImageLayout newLayout)
        {
            if (setupCommanBuffer == CommandBuffer.Null)
            {
                // Create command buffer
                CommandBuffer setupCommandBuffer;
                var           allocateInfo = new CommandBufferAllocateInfo
                {
                    StructureType      = StructureType.CommandBufferAllocateInfo,
                    CommandPool        = commandPool,
                    Level              = CommandBufferLevel.Primary,
                    CommandBufferCount = 1,
                };
                device.AllocateCommandBuffers(ref allocateInfo, &setupCommandBuffer);
                setupCommanBuffer = setupCommandBuffer;

                // Begin command buffer
                var inheritanceInfo = new CommandBufferInheritanceInfo {
                    StructureType = StructureType.CommandBufferInheritanceInfo
                };
                var beginInfo = new CommandBufferBeginInfo
                {
                    StructureType   = StructureType.CommandBufferBeginInfo,
                    InheritanceInfo = new IntPtr(&inheritanceInfo)
                };
                setupCommanBuffer.Begin(ref beginInfo);
            }

            var imageMemoryBarrier = new ImageMemoryBarrier
            {
                StructureType    = StructureType.ImageMemoryBarrier,
                OldLayout        = oldLayout,
                NewLayout        = newLayout,
                Image            = image,
                SubresourceRange = new ImageSubresourceRange(imageAspect, 0, 1, 0, 1)
            };

            switch (newLayout)
            {
            case ImageLayout.TransferDestinationOptimal:
                imageMemoryBarrier.DestinationAccessMask = AccessFlags.TransferRead;
                break;

            case ImageLayout.ColorAttachmentOptimal:
                imageMemoryBarrier.DestinationAccessMask = AccessFlags.ColorAttachmentWrite;
                break;

            case ImageLayout.DepthStencilAttachmentOptimal:
                imageMemoryBarrier.DestinationAccessMask = AccessFlags.DepthStencilAttachmentWrite;
                break;

            case ImageLayout.ShaderReadOnlyOptimal:
                imageMemoryBarrier.DestinationAccessMask = AccessFlags.ShaderRead | AccessFlags.InputAttachmentRead;
                break;
            }

            var sourceStages      = PipelineStageFlags.TopOfPipe;
            var destinationStages = PipelineStageFlags.TopOfPipe;

            setupCommanBuffer.PipelineBarrier(sourceStages, destinationStages, DependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier);
        }
        private void InitializeFromImpl(DataBox[] dataBoxes = null)
        {
            NativeFormat = VulkanConvertExtensions.ConvertPixelFormat(ViewFormat);
            HasStencil = IsStencilFormat(ViewFormat);
            
            NativeImageAspect = IsDepthStencil ? ImageAspectFlags.Depth : ImageAspectFlags.Color;
            if (HasStencil)
                NativeImageAspect |= ImageAspectFlags.Stencil;

            // For depth-stencil formats, automatically fall back to a supported one
            if (IsDepthStencil && HasStencil)
            {
                NativeFormat = GetFallbackDepthStencilFormat(GraphicsDevice, NativeFormat);
            }

            if (Usage == GraphicsResourceUsage.Staging)
            {
                if (NativeImage != SharpVulkan.Image.Null)
                    throw new InvalidOperationException();

                if (isNotOwningResources)
                    throw new InvalidOperationException();

                if (ParentTexture != null)
                {
                    // Create only a view
                    NativeBuffer = ParentTexture.NativeBuffer;
                    NativeMemory = ParentTexture.NativeMemory;
                }
                else
                {
                    CreateBuffer();

                    if (dataBoxes != null)
                        throw new InvalidOperationException();
                }
            }
            else
            {
                if (NativeImage != SharpVulkan.Image.Null)
                    throw new InvalidOperationException();

                NativeLayout =
                    IsRenderTarget ? ImageLayout.ColorAttachmentOptimal :
                    IsDepthStencil ? ImageLayout.DepthStencilAttachmentOptimal :
                    IsShaderResource ? ImageLayout.ShaderReadOnlyOptimal :
                    ImageLayout.General;

                if (NativeLayout == ImageLayout.TransferDestinationOptimal)
                    NativeAccessMask = AccessFlags.TransferRead;

                if (NativeLayout == ImageLayout.ColorAttachmentOptimal)
                    NativeAccessMask = AccessFlags.ColorAttachmentWrite;

                if (NativeLayout == ImageLayout.DepthStencilAttachmentOptimal)
                    NativeAccessMask = AccessFlags.DepthStencilAttachmentWrite;

                if (NativeLayout == ImageLayout.ShaderReadOnlyOptimal)
                    NativeAccessMask = AccessFlags.ShaderRead | AccessFlags.InputAttachmentRead;

                NativePipelineStageMask =
                    IsRenderTarget ? PipelineStageFlags.ColorAttachmentOutput :
                    IsDepthStencil ? PipelineStageFlags.ColorAttachmentOutput | PipelineStageFlags.EarlyFragmentTests | PipelineStageFlags.LateFragmentTests :
                    IsShaderResource ? PipelineStageFlags.VertexInput | PipelineStageFlags.FragmentShader :
                    PipelineStageFlags.None;

                if (ParentTexture != null)
                {
                    // Create only a view
                    NativeImage = ParentTexture.NativeImage;
                    NativeMemory = ParentTexture.NativeMemory;
                }
                else
                {
                    if (!isNotOwningResources)
                    {
                        CreateImage();

                        InitializeImage(dataBoxes);
                    }
                }

                if (!isNotOwningResources)
                {
                    NativeImageView = GetImageView(ViewType, ArraySlice, MipLevel);
                    NativeColorAttachmentView = GetColorAttachmentView(ViewType, ArraySlice, MipLevel);
                    NativeDepthStencilView = GetDepthStencilView();
                }
            }
        }
Example #29
0
 public ImageSubresourceRange(ImageAspectFlags aspectMask)
     : this(aspectMask, 0, Vulkan.RemainingArrayLayers, 0, Vulkan.RemainingMipLevels)
 {
 }
        public FrameBufferAttachment(String Name, Image image, ImageViewType view2D, Format format, ImageAspectFlags color, uint levelCount, uint layercount)
        {
            this.Name = Name;
            var viewCreateInfo = new ImageViewCreateInfo
            {
                Image            = image,
                ViewType         = view2D,
                Format           = format,
                SubresourceRange = new ImageSubresourceRange
                {
                    AspectMask = color,
                    LevelCount = levelCount,
                    LayerCount = layercount
                }
            };

            VulkanRenderer.SelectedLogicalDevice.CreateImageView(this, viewCreateInfo);
            viewCreateInfo.Dispose();
        }
Example #31
0
        public static ImageViewCreateInfo ImageViewCreateInfo(Format format, Image image, ImageAspectFlags aspectFlags, ImageViewType viewType = ImageViewType.ImageViewType2D)
        {
            return(new ImageViewCreateInfo()
            {
                SType = StructureType.ImageViewCreateInfo,

                Image = image,

                ViewType = viewType,
                Format = format,

                Components = new ComponentMapping()
                {
                    R = ComponentSwizzle.Identity,
                    G = ComponentSwizzle.Identity,
                    B = ComponentSwizzle.Identity,
                    A = ComponentSwizzle.Identity
                },

                SubresourceRange = new ImageSubresourceRange()
                {
                    AspectMask = aspectFlags,
                    BaseArrayLayer = 0,
                    LayerCount = 1,
                    BaseMipLevel = 0,
                    LevelCount = 1
                }
            });
        }
Example #32
0
 /// <summary>
 ///
 /// </summary>
 public ClearAttachment(ImageAspectFlags aspectMask, uint colorAttachment, ClearValue clearValue)
 {
     this.AspectMask      = aspectMask;
     this.ColorAttachment = colorAttachment;
     this.ClearValue      = clearValue;
 }
Example #33
0
        internal FrameBufferAttachment CreateAttachment(string AttachmentLookupID, Format format, ImageViewType view2D, Image image, ImageAspectFlags color, uint levelCount, uint layercount)
        {
            myImage = image;
            if (Initialized)
            {
                throw new Exception("Attempted to add attachment to initialized Framebuffer!");
            }
            if (myAttachments.ContainsKey(AttachmentLookupID))
            {
                throw new Exception("A framebuffer attachment with ID: " + AttachmentLookupID + " was added to frame buffer twice.");
            }
            var myAttache = new FrameBufferAttachment(AttachmentLookupID, image, view2D, format, color, levelCount, layercount);

            myAttachments[AttachmentLookupID] = myAttache;
            return(myAttache);
        }
Example #34
0
        private void InitializeFromImpl(DataBox[] dataBoxes = null)
        {
            NativeFormat = VulkanConvertExtensions.ConvertPixelFormat(ViewFormat);
            HasStencil   = IsStencilFormat(ViewFormat);

            NativeImageAspect = IsDepthStencil ? ImageAspectFlags.Depth : ImageAspectFlags.Color;
            if (HasStencil)
            {
                NativeImageAspect |= ImageAspectFlags.Stencil;
            }

            // For depth-stencil formats, automatically fall back to a supported one
            if (IsDepthStencil && HasStencil)
            {
                NativeFormat = GetFallbackDepthStencilFormat(GraphicsDevice, NativeFormat);
            }

            if (Usage == GraphicsResourceUsage.Staging)
            {
                if (NativeImage != SharpVulkan.Image.Null)
                {
                    throw new InvalidOperationException();
                }

                if (isNotOwningResources)
                {
                    throw new InvalidOperationException();
                }

                if (ParentTexture != null)
                {
                    // Create only a view
                    NativeBuffer = ParentTexture.NativeBuffer;
                    NativeMemory = ParentTexture.NativeMemory;
                }
                else
                {
                    CreateBuffer();

                    if (dataBoxes != null)
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
            else
            {
                if (NativeImage != SharpVulkan.Image.Null)
                {
                    throw new InvalidOperationException();
                }

                NativeLayout =
                    IsRenderTarget ? ImageLayout.ColorAttachmentOptimal :
                    IsDepthStencil ? ImageLayout.DepthStencilAttachmentOptimal :
                    IsShaderResource ? ImageLayout.ShaderReadOnlyOptimal :
                    ImageLayout.General;

                if (NativeLayout == ImageLayout.TransferDestinationOptimal)
                {
                    NativeAccessMask = AccessFlags.TransferRead;
                }

                if (NativeLayout == ImageLayout.ColorAttachmentOptimal)
                {
                    NativeAccessMask = AccessFlags.ColorAttachmentWrite;
                }

                if (NativeLayout == ImageLayout.DepthStencilAttachmentOptimal)
                {
                    NativeAccessMask = AccessFlags.DepthStencilAttachmentWrite;
                }

                if (NativeLayout == ImageLayout.ShaderReadOnlyOptimal)
                {
                    NativeAccessMask = AccessFlags.ShaderRead | AccessFlags.InputAttachmentRead;
                }

                NativePipelineStageMask =
                    IsRenderTarget ? PipelineStageFlags.ColorAttachmentOutput :
                    IsDepthStencil ? PipelineStageFlags.ColorAttachmentOutput | PipelineStageFlags.EarlyFragmentTests | PipelineStageFlags.LateFragmentTests :
                    IsShaderResource ? PipelineStageFlags.VertexInput | PipelineStageFlags.FragmentShader :
                    PipelineStageFlags.None;

                if (ParentTexture != null)
                {
                    // Create only a view
                    NativeImage  = ParentTexture.NativeImage;
                    NativeMemory = ParentTexture.NativeMemory;
                }
                else
                {
                    if (!isNotOwningResources)
                    {
                        CreateImage();

                        InitializeImage(dataBoxes);
                    }
                }

                if (!isNotOwningResources)
                {
                    NativeImageView           = GetImageView(ViewType, ArraySlice, MipLevel);
                    NativeColorAttachmentView = GetColorAttachmentView(ViewType, ArraySlice, MipLevel);
                    NativeDepthStencilView    = GetDepthStencilView();
                }
            }
        }
Example #35
0
        public FrameBufferAttachment CreateAttachment(string AttachmentLookupID, Format myFormat, ImageType myType, ImageViewType view2D, ImageUsageFlags myImageFlag, ImageAspectFlags color, ImageTiling myTiles, SampleCountFlags mySampleCount, uint levelCount, uint layercount)
        {        //TODO: Write exception class
            if (Initialized)
            {
                throw new Exception("Attempted to add attachment to initialized Framebuffer!");
            }
            if (myAttachments.ContainsKey(AttachmentLookupID))
            {
                throw new Exception("A framebuffer attachment with ID: " + AttachmentLookupID + " was added to frame buffer twice.");
            }
            ImageCreateInfo myInfo = new ImageCreateInfo()
            {
                ImageType = myType, MipLevels = 1, Format = myFormat, Extent = new Extent3D()
                {
                    Width = myFramebufferInfo.Width, Height = myFramebufferInfo.Height, Depth = 1
                }, ArrayLayers = layercount, Samples = mySampleCount, Tiling = myTiles, Usage = myImageFlag
            };

            myImage = new Image(myInfo);
            var Return = this.CreateAttachment(AttachmentLookupID, myFormat, view2D, myImage, color, levelCount, layercount);

            myAttachments[AttachmentLookupID] = Return;
            myInfo.Dispose(false);
            return(Return);
        }