Beispiel #1
0
        private void createImageViews()
        {
            swapChainImageViews = new VkImageView[swapChainImages.Length];

            for (int i = 0; i < swapChainImages.Length; i++)
            {
                VkImageViewCreateInfo createInfo = new VkImageViewCreateInfo();
                createInfo.sType        = VkStructureType.VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
                createInfo.image        = swapChainImages[i];
                createInfo.viewType     = VkImageViewType.VK_IMAGE_VIEW_TYPE_2D;
                createInfo.format       = swapChainImageFormat;
                createInfo.components.r = VkComponentSwizzle.VK_COMPONENT_SWIZZLE_IDENTITY;
                createInfo.components.g = VkComponentSwizzle.VK_COMPONENT_SWIZZLE_IDENTITY;
                createInfo.components.b = VkComponentSwizzle.VK_COMPONENT_SWIZZLE_IDENTITY;
                createInfo.components.a = VkComponentSwizzle.VK_COMPONENT_SWIZZLE_IDENTITY;
                createInfo.subresourceRange.aspectMask     = VkImageAspectFlagBits.VK_IMAGE_ASPECT_COLOR_BIT;
                createInfo.subresourceRange.baseMipLevel   = 0;
                createInfo.subresourceRange.levelCount     = 1;
                createInfo.subresourceRange.baseArrayLayer = 0;
                createInfo.subresourceRange.layerCount     = 1;

                VkImageView imageView = null;
                VkResult    result    = Vulkan.vkCreateImageView(device, createInfo, default(VkAllocationCallbacks), out imageView);
                if (result != VkResult.VK_SUCCESS)
                {
                    throw Program.Throw("failed to create image views!", result);
                }
                swapChainImageViews[i] = imageView;
            }
        }
Beispiel #2
0
        public void CreateView(VkImageViewType type = VkImageViewType.ImageView2D, VkImageAspectFlags aspectFlags = VkImageAspectFlags.Color,
                               uint layerCount      = 1,
                               uint baseMipLevel    = 0, uint levelCount = 1, uint baseArrayLayer = 0,
                               VkComponentSwizzle r = VkComponentSwizzle.R,
                               VkComponentSwizzle g = VkComponentSwizzle.G,
                               VkComponentSwizzle b = VkComponentSwizzle.B,
                               VkComponentSwizzle a = VkComponentSwizzle.A)
        {
            VkImageView           view     = default(VkImageView);
            VkImageViewCreateInfo viewInfo = VkImageViewCreateInfo.New();

            viewInfo.image        = handle;
            viewInfo.viewType     = type;
            viewInfo.format       = Format;
            viewInfo.components.r = r;
            viewInfo.components.g = g;
            viewInfo.components.b = b;
            viewInfo.components.a = a;
            viewInfo.subresourceRange.aspectMask     = aspectFlags;
            viewInfo.subresourceRange.baseMipLevel   = baseMipLevel;
            viewInfo.subresourceRange.levelCount     = levelCount;
            viewInfo.subresourceRange.baseArrayLayer = baseArrayLayer;
            viewInfo.subresourceRange.layerCount     = layerCount;

            Utils.CheckResult(vkCreateImageView(Dev.VkDev, ref viewInfo, IntPtr.Zero, out view));

            if (Descriptor.imageView.Handle != 0)
            {
                Dev.DestroyImageView(Descriptor.imageView);
            }
            Descriptor.imageView = view;
        }
Beispiel #3
0
        protected virtual void SetupFrameBuffer()
        {
            var attachments = new VkImageView[2];

            // Depth/Stencil attachment is the same for all frame buffers
            attachments[1] = DepthStencil.View;

            VkFramebufferCreateInfo frameBufferCreateInfo = new VkFramebufferCreateInfo();

            frameBufferCreateInfo.sType       = FramebufferCreateInfo;
            frameBufferCreateInfo.renderPass  = renderPass;
            frameBufferCreateInfo.attachments = attachments;
            frameBufferCreateInfo.width       = width;
            frameBufferCreateInfo.height      = height;
            frameBufferCreateInfo.layers      = 1;

            // Create frame buffers for every swap chain image
            frameBuffers = new VkFramebuffer[Swapchain.ImageCount];
            for (uint i = 0; i < frameBuffers.Length; i++)
            {
                attachments[0] = Swapchain.Buffers[i].View;
                frameBufferCreateInfo.attachments = attachments;
                VkFramebuffer framebuffer;
                vkCreateFramebuffer(device, &frameBufferCreateInfo, null, &framebuffer);
                frameBuffers[i] = framebuffer;
            }
        }
        private VkImageView[] CreateImageViews()
        {
            var imageViews = new VkImageView[SwapchainImages.Length];

            for (int i = 0; i < SwapchainImages.Length; i++)
            {
                VkImageSubresourceRange range = new VkImageSubresourceRange
                {
                    aspectMask     = VkImageAspectFlags.Color,
                    baseMipLevel   = 0,
                    levelCount     = 1,
                    baseArrayLayer = 0,
                    layerCount     = 1
                };

                VkImageViewCreateInfo createInfo = new VkImageViewCreateInfo
                {
                    sType            = VkStructureType.ImageViewCreateInfo,
                    pNext            = null,
                    format           = SwapchainFormat,
                    viewType         = VkImageViewType.Image2D,
                    subresourceRange = range,
                    image            = SwapchainImages[i]
                };

                VkImageView imageView;
                vkCreateImageView(Context.Device, &createInfo, null, out imageView);

                imageViews[i] = imageView;
            }
            return(imageViews);
        }
Beispiel #5
0
 private VulkanImage(VulkanContext ctx, VkImage image, VkDeviceMemory memory, VkImageView view, VkFormat format)
 {
     Image    = image;
     Memory   = memory;
     View     = view;
     Format   = format;
     this.ctx = ctx;
 }
Beispiel #6
0
 public FTexture(VkDevice device, VkPhysicalDevice physicalDevice, int cmdPoolID, VkQueue queue, string[] paths,
                 VkFormat format, int width, int height, uint mipLevels = 1)
 {
     MipLevels = mipLevels;
     image     = LoadTexture(device, physicalDevice, cmdPoolID, queue, paths, MipLevels);
     imageView = CreateColourImageArrayView(device, image, paths.Length, format, MipLevels);
     InitMips(device, queue, image, width, height, MipLevels, (uint)paths.Length, cmdPoolID);
 }
Beispiel #7
0
        public static VkDescriptorImageInfo descriptorImageInfo(VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout)
        {
            VkDescriptorImageInfo descriptorImageInfo = new VkDescriptorImageInfo();

            descriptorImageInfo.sampler     = sampler;
            descriptorImageInfo.imageView   = imageView;
            descriptorImageInfo.imageLayout = imageLayout;
            return(descriptorImageInfo);
        }
Beispiel #8
0
        private void DisposeVulkanSwapChainImageView(VkImageView vulkanSwapchainImageView)
        {
            _state.AssertDisposing();

            if (vulkanSwapchainImageView != VK_NULL_HANDLE)
            {
                vkDestroyImageView(VulkanGraphicsDevice.VulkanDevice, vulkanSwapchainImageView, pAllocator: null);
            }
        }
Beispiel #9
0
 public void SetFullHandles(VkImage image, VkImageView attachmentView,
                            VkImageLayout layout, VkAccessFlags accessMask,
                            VkFormat nativeFormat, VkImageAspectFlags aspect)
 {
     NativeImage = image;
     NativeColorAttachmentView = attachmentView;
     NativeLayout      = layout;
     NativeAccessMask  = accessMask;
     NativeFormat      = nativeFormat;
     NativeImageAspect = aspect;
 }
Beispiel #10
0
        protected VkFramebuffer[] CreateFramebuffers(VkDevice device, VkImage[] images,
                                                     VkSurfaceFormatKHR surfaceFormat, VkRenderPass renderPass,
                                                     VkSurfaceCapabilitiesKHR surfaceCapabilities)
        {
            var displayViews = new VkImageView[images.Length];
            var viewInfo     = new VkImageViewCreateInfo {
                sType = VkStructureType.ImageViewCreateInfo
            };

            viewInfo.viewType   = VkImageViewType._2d;
            viewInfo.format     = surfaceFormat.format;
            viewInfo.components = new VkComponentMapping {
                r = VkComponentSwizzle.R,
                g = VkComponentSwizzle.G,
                b = VkComponentSwizzle.B,
                a = VkComponentSwizzle.A
            };
            viewInfo.subresourceRange = new VkImageSubresourceRange {
                aspectMask = VkImageAspectFlagBits.Color,
                levelCount = 1,
                layerCount = 1
            };
            for (int i = 0; i < images.Length; i++)
            {
                viewInfo.image = images[i];
                //displayViews[i] = device.CreateImageView(ref info);
                VkImageView view;
                vkAPI.vkCreateImageView(device, &viewInfo, null, &view).Check();
                displayViews[i] = view;
            }

            var framebuffers = new VkFramebuffer[images.Length];
            var fbInfo       = new VkFramebufferCreateInfo {
                sType = VkStructureType.FramebufferCreateInfo
            };

            fbInfo.layers     = 1;
            fbInfo.renderPass = renderPass;
            fbInfo.width      = surfaceCapabilities.currentExtent.width;
            fbInfo.height     = surfaceCapabilities.currentExtent.height;
            for (int i = 0; i < images.Length; i++)
            {
                fbInfo.attachments = displayViews[i];
                //framebuffers[i] = device.CreateFramebuffer(ref info);
                VkFramebuffer framebuffer;
                vkAPI.vkCreateFramebuffer(device, &fbInfo, null, &framebuffer).Check();
                framebuffers[i] = framebuffer;
            }

            fbInfo.Free();

            return(framebuffers);
        }
Beispiel #11
0
        /// <inheritdoc/>
        protected internal override void OnDestroyed()
        {
            if (ParentTexture != null || isNotOwningResources)
            {
                NativeImage  = VkImage.Null;
                NativeMemory = VkDeviceMemory.Null;
            }

            if (!isNotOwningResources)
            {
                if (NativeMemory != VkDeviceMemory.Null)
                {
                    GraphicsDevice.Collect(NativeMemory);
                    NativeMemory = VkDeviceMemory.Null;
                    SharedHandle = IntPtr.Zero;
                }

                if (NativeImage != VkImage.Null)
                {
                    GraphicsDevice.Collect(NativeImage);
                    NativeImage = VkImage.Null;
                }

                if (NativeBuffer != VkBuffer.Null)
                {
                    GraphicsDevice.Collect(NativeBuffer);
                    NativeBuffer = VkBuffer.Null;
                }

                if (NativeImageView != VkImageView.Null)
                {
                    GraphicsDevice.Collect(NativeImageView);
                    NativeImageView = VkImageView.Null;
                }

                if (NativeColorAttachmentView != VkImageView.Null)
                {
                    GraphicsDevice.Collect(NativeColorAttachmentView);
                    NativeColorAttachmentView = VkImageView.Null;
                }

                if (NativeDepthStencilView != VkImageView.Null)
                {
                    GraphicsDevice.Collect(NativeDepthStencilView);
                    NativeDepthStencilView = VkImageView.Null;
                }
            }

            base.OnDestroyed();
        }
Beispiel #12
0
        public static void SetDebugMarkerName(this VkImageView obj, Device dev, string name)
        {
            if (!dev.DebugMarkersEnabled)
            {
                return;
            }
            VkDebugMarkerObjectNameInfoEXT dmo = new VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT.ImageViewEXT,
                                                                                    obj.Handle)
            {
                pObjectName = name.Pin()
            };

            Utils.CheckResult(vkDebugMarkerSetObjectNameEXT(dev.VkDev, ref dmo));
            name.Unpin();
        }
Beispiel #13
0
        public static void SetDebugMarkerName(this VkImageView obj, Device dev, string name)
        {
            if (!dev.debugUtilsEnabled)
            {
                return;
            }
            VkDebugUtilsObjectNameInfoEXT dmo = new VkDebugUtilsObjectNameInfoEXT(VkObjectType.ImageView,
                                                                                  (ulong)obj.Handle)
            {
                pObjectName = name.Pin()
            };

            Utils.CheckResult(vkSetDebugUtilsObjectNameEXT(dev.VkDev, ref dmo));
            name.Unpin();
        }
Beispiel #14
0
        private void CreateDepthImageView()
        {
            VkImageViewCreateInfo createInfo = VkImageViewCreateInfo.New();

            createInfo.image    = depthImage;
            createInfo.viewType = VkImageViewType.Image2D;
            createInfo.format   = VkFormat.D32Sfloat;
            createInfo.subresourceRange.aspectMask = VkImageAspectFlags.Depth;
            createInfo.subresourceRange.layerCount = 1;
            createInfo.subresourceRange.levelCount = 1;

            VkImageView view = VkImageView.Null;

            Assert(vkCreateImageView(device, &createInfo, null, &view));
            this.depthImageView = view;
        }
Beispiel #15
0
        void CreateImageView(VkImage image, VkFormat format, ref VkImageView imageView)
        {
            var info = new VkImageViewCreateInfo();

            info.image    = image;
            info.viewType = VkImageViewType._2D;
            info.format   = format;
            info.subresourceRange.aspectMask     = VkImageAspectFlags.ColorBit;
            info.subresourceRange.baseMipLevel   = 0;;
            info.subresourceRange.levelCount     = 1;
            info.subresourceRange.baseArrayLayer = 0;
            info.subresourceRange.layerCount     = 1;

            imageView?.Dispose();
            imageView = new VkImageView(device, info);
        }
Beispiel #16
0
        public static VkImageView CreateColourImageArrayView(VkDevice device, VkImage image, int layers, VkFormat imageFormat, uint mipLevels)
        {
            VkImageViewCreateInfo createInfo = VkImageViewCreateInfo.New();

            createInfo.image    = image;
            createInfo.viewType = VkImageViewType.Image2DArray;
            createInfo.format   = imageFormat;
            createInfo.subresourceRange.aspectMask = VkImageAspectFlags.Color;
            createInfo.subresourceRange.layerCount = (uint)layers;
            createInfo.subresourceRange.levelCount = mipLevels;

            VkImageView view = VkImageView.Null;

            Assert(vkCreateImageView(device, &createInfo, null, &view));
            return(view);
        }
Beispiel #17
0
        void CreateImageViews()
        {
            if (swapchainImageViews != null)
            {
                foreach (var iv in swapchainImageViews)
                {
                    iv.Dispose();
                }
            }

            swapchainImageViews = new List <VkImageView>();
            foreach (var image in swapchainImages)
            {
                VkImageView temp = null;
                CreateImageView(image, swapchainImageFormat, ref temp);
                swapchainImageViews.Add(temp);
            }
        }
Beispiel #18
0
        public unsafe ImageView(
            Image image,
            VkImageAspectFlags aspectMask
            )
        {
            _device = image.Device;
            _image  = image;
            var imageViewInfo = new VkImageViewCreateInfo
            {
                sType      = VkStructureType.ImageViewCreateInfo,
                image      = image.Handle,
                viewType   = VkImageViewType.Image2D,
                format     = image.Format,
                components = new VkComponentMapping
                {
                    r = VkComponentSwizzle.Identity,
                    g = VkComponentSwizzle.Identity,
                    b = VkComponentSwizzle.Identity,
                    a = VkComponentSwizzle.Identity
                },
                subresourceRange = new VkImageSubresourceRange
                {
                    aspectMask     = aspectMask,
                    baseMipLevel   = 0,
                    levelCount     = image.MipLevel,
                    baseArrayLayer = 0,
                    layerCount     = 1
                }
            };

            VkImageView imageView;

            if (VulkanNative.vkCreateImageView(
                    _device.Handle,
                    &imageViewInfo,
                    null,
                    &imageView
                    ) != VkResult.Success)
            {
                throw new Exception("failed to create image view");
            }
            _handle = imageView;
        }
Beispiel #19
0
        internal void Initialize(int w, int h)
        {
            //create_buffer_image(0);


            create_image(w, h);

            // For depth-stencil formats, automatically fall back to a supported one
            if (IsDepthStencil)
            {
                image_view = get_depth_stencil_view();
            }

            if (IsShaderResource)
            {
                create_buffer_image();

                image_view = get_image_view();
            }
        }
Beispiel #20
0
        static VkFramebuffer CreateFramebuffer(VkDevice device, VkRenderPass pass, VkImageView imageView, VkImageView depthImageView)
        {
            VkImageView[] imageViews = new VkImageView[] {
                imageView,
                depthImageView
            };

            VkFramebufferCreateInfo createInfo = VkFramebufferCreateInfo.New();

            createInfo.renderPass      = pass;
            createInfo.attachmentCount = (uint)imageViews.Length;

            fixed(VkImageView *ptr = imageViews)
            createInfo.pAttachments = ptr;

            createInfo.width  = (uint)width;
            createInfo.height = (uint)height;
            createInfo.layers = 1;

            VkFramebuffer framebuffer = VkFramebuffer.Null;

            Assert(vkCreateFramebuffer(device, &createInfo, null, &framebuffer));
            return(framebuffer);
        }
Beispiel #21
0
 public static extern VkResult CreateImageView(
     VkDevice device,
     ref VkImageViewCreateInfo pCreateInfo,
     IntPtr pAllocator,
     out VkImageView pView
     );
Beispiel #22
0
 public override VkResult CreateImageView(VkImageViewCreateInfo createInfo, out VkImageView imageView)
 {
     imageView = new DummyImageView();
     return(VkResult.VK_SUCCESS);
 }
Beispiel #23
0
 public override void DestroyImageView(VkImageView imageView)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
        public static VkResult vkCreateImageView(VkDevice device, VkImageViewCreateInfo createInfo, VkAllocationCallbacks pAllocator, out VkImageView imageView)
        {
            VkPreconditions.CheckNull(device, nameof(device));

            return(GetDevice(device).CreateImageView(createInfo, out imageView));
        }
Beispiel #25
0
        public Framebuffer(VkDevice Device, int Width, int Height)
        {
            _Device           = Device;
            _Width            = Width;
            _Height           = Height;
            _FrameBufferColor = _Device.CreateImage(VkImageCreateFlag.NONE,
                                                    VkFormat.VK_FORMAT_B8G8R8A8_SRGB,
                                                    Width, Height,
                                                    1, 1,
                                                    VkSampleCountFlag.VK_SAMPLE_COUNT_1,
                                                    VkImageTiling.VK_IMAGE_TILING_OPTIMAL,
                                                    VkImageUsageFlag.VK_IMAGE_USAGE_COLOR_ATTACHMENT,
                                                    VkSharingMode.VK_SHARING_MODE_EXCLUSIVE,
                                                    null,
                                                    VkImageLayout.VK_IMAGE_LAYOUT_UNDEFINED);

            _ImageSize = _FrameBufferColor.MemoryRequirements.size;


            // We will back this image with Device Accessible Memomy so we can map it an copy
            // the content from the Host.
            // To do so we need to find the right memory type first.
            VkMemoryType deviceMemory = new VkMemoryType();

            foreach (VkMemoryType memoryType in _FrameBufferColor.MemoryRequirements.memoryTypes)
            {
                // Pick the first memory type that can be mapped into host memory
                if ((memoryType.propertyFlags & VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_DEVICE_LOCAL) != 0)
                {
                    deviceMemory = memoryType;
                    break;
                }
            }

            VkDeviceMemory FrameBufferMemory = _Device.AllocateMemory(_FrameBufferColor.MemoryRequirements.size, deviceMemory);

            _FrameBufferColor.BindMemory(FrameBufferMemory, 0);

            // Allocate the host visible memory to transfer the framebuffer
            _TransferBuffer = _Device.CreateBuffer(0, _FrameBufferColor.MemoryRequirements.size, VkBufferUsageFlag.VK_BUFFER_USAGE_TRANSFER_DST, VkSharingMode.VK_SHARING_MODE_EXCLUSIVE, new VkQueueFamilyProperties[] { _Device.Queues[0].Family });

            // We will use a host visible buffer so we can map it an copy
            // the content from the Host.
            // To do so we need to find the right memory type first.
            VkMemoryType hostMemory = new VkMemoryType();

            foreach (VkMemoryType memoryType in _TransferBuffer.MemoryRequirements.memoryTypes)
            {
                // Pick the first memory type that can be mapped into host memory
                if ((memoryType.propertyFlags & VkMemoryPropertyFlags.VK_MEMORY_PROPERTY_HOST_VISIBLE) != 0)
                {
                    hostMemory = memoryType;
                    break;
                }
            }

            VkDeviceMemory TransferBufferMemory = _Device.AllocateMemory(_ImageSize, hostMemory);

            _TransferBuffer.BindMemory(TransferBufferMemory, 0);
            _TransferBufferPtr = TransferBufferMemory.Map(0, _ImageSize, VkMemoryMapFlag.NONE);


            VkImageView imageView = _FrameBufferColor.CreateImageView(VkImageViewType.VK_IMAGE_VIEW_TYPE_2D, new VkImageSubresourceRange()
            {
                aspectMask = VkImageAspectFlag.VK_IMAGE_ASPECT_COLOR_BIT, baseArrayLayer = 0, baseMipLevel = 0, layerCount = 1, levelCount = 1
            });


            VkAttachmentDescription colorAttachment = new VkAttachmentDescription();

            colorAttachment.format         = _FrameBufferColor.Format;
            colorAttachment.samples        = VkSampleCountFlag.VK_SAMPLE_COUNT_1;
            colorAttachment.loadOp         = VkAttachmentLoadOp.VK_ATTACHMENT_LOAD_OP_CLEAR;
            colorAttachment.storeOp        = VkAttachmentStoreOp.VK_ATTACHMENT_STORE_OP_STORE;
            colorAttachment.stencilLoadOp  = VkAttachmentLoadOp.VK_ATTACHMENT_LOAD_OP_DONT_CARE;
            colorAttachment.stencilStoreOp = VkAttachmentStoreOp.VK_ATTACHMENT_STORE_OP_DONT_CARE;
            colorAttachment.initialLayout  = VkImageLayout.VK_IMAGE_LAYOUT_UNDEFINED;
            colorAttachment.finalLayout    = VkImageLayout.VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

            VkAttachmentReference colorAttachmentReference = new VkAttachmentReference();

            colorAttachmentReference.attachment = 0;
            colorAttachmentReference.layout     = VkImageLayout.VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

            VkSubpassDescription subpass = new VkSubpassDescription();

            subpass.pipelineBindPoint      = VkPipelineBindPoint.VK_PIPELINE_BIND_POINT_GRAPHICS;
            subpass.colorAttachments       = new VkAttachmentReference[] { colorAttachmentReference };
            subpass.depthStencilAttachment = null;
            subpass.inputAttachments       = null;
            subpass.preserveAttachments    = null;
            subpass.resolveAttachments     = null;

            VkSubpassDependency dependency = new VkSubpassDependency();

            dependency.srcSubpass    = VkSubpassDependency.VK_SUBPASS_EXTERNAL;
            dependency.dstSubpass    = 0;
            dependency.srcStageMask  = VkPipelineStageFlag.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT;
            dependency.srcAccessMask = 0;
            dependency.dstStageMask  = VkPipelineStageFlag.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT;
            dependency.dstAccessMask = VkAccessFlag.VK_ACCESS_COLOR_ATTACHMENT_READ | VkAccessFlag.VK_ACCESS_COLOR_ATTACHMENT_WRITE;

            _RenderPass = _Device.CreateRenderPass(new VkAttachmentDescription[] { colorAttachment },
                                                   new VkSubpassDescription[] { subpass },
                                                   new VkSubpassDependency[] { dependency });

            _Framebuffer = _Device.CreateFramebuffer(_RenderPass, new VkImageView[] { imageView }, (uint)Width, (uint)Height, 1);
        }
Beispiel #26
0
 public static extern void DestroyImageView(
     VkDevice device,
     VkImageView imageView,
     IntPtr pAllocator
     );
Beispiel #27
0
        public static void vkDestroyImageView(VkDevice device, VkImageView imageView, VkAllocationCallbacks pAllocator)
        {
            VkPreconditions.CheckNull(device, nameof(device));

            GetDevice(device).DestroyImageView(imageView);
        }
Beispiel #28
0
 internal void SetNativeHandles(VkImage image, VkImageView attachmentView)
 {
     NativeImage = image;
     NativeColorAttachmentView = attachmentView;
 }
Beispiel #29
0
        private void InitializeFromImpl(DataBox[] dataBoxes = null)
        {
            NativeFormat = VulkanConvertExtensions.ConvertPixelFormat(ViewFormat);
            HasStencil   = IsStencilFormat(ViewFormat);

            NativeImageAspect = IsDepthStencil ? VkImageAspectFlags.Depth : VkImageAspectFlags.Color;
            if (HasStencil)
            {
                NativeImageAspect |= VkImageAspectFlags.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 != VkImage.Null)
                {
                    throw new InvalidOperationException();
                }

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

                NativeAccessMask = VkAccessFlags.HostRead | VkAccessFlags.HostWrite;

                NativePipelineStageMask = VkPipelineStageFlags.Host;

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

                    if (dataBoxes != null && dataBoxes.Length > 0)
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
            else
            {
                if (NativeImage != VkImage.Null)
                {
                    throw new InvalidOperationException();
                }

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

                if (NativeLayout == VkImageLayout.TransferDstOptimal)
                {
                    NativeAccessMask = VkAccessFlags.TransferRead;
                }

                if (NativeLayout == VkImageLayout.ColorAttachmentOptimal)
                {
                    NativeAccessMask = VkAccessFlags.ColorAttachmentWrite;
                }

                if (NativeLayout == VkImageLayout.DepthStencilAttachmentOptimal)
                {
                    NativeAccessMask = VkAccessFlags.DepthStencilAttachmentWrite;
                }

                if (NativeLayout == VkImageLayout.ShaderReadOnlyOptimal)
                {
                    NativeAccessMask = VkAccessFlags.ShaderRead | VkAccessFlags.InputAttachmentRead;
                }

                NativePipelineStageMask =
                    IsRenderTarget ? VkPipelineStageFlags.ColorAttachmentOutput :
                    IsDepthStencil ? VkPipelineStageFlags.ColorAttachmentOutput | VkPipelineStageFlags.EarlyFragmentTests | VkPipelineStageFlags.LateFragmentTests :
                    IsShaderResource ? VkPipelineStageFlags.VertexInput | VkPipelineStageFlags.FragmentShader :
                    VkPipelineStageFlags.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();
                }
            }
        }
 public abstract void DestroyImageView(VkImageView imageView);