public PlatformRenderTexture2D(PlatformRenderContext context, Format format, int width, int height, TextureParams textureParams) : base(context, format, width, height, false, true, textureParams) { colorFormat = VulkanHelper.GetVKFormat(format); CreateDepthStencilBuffer(); CreateRenderPass(); CreateFramebuffer(); }
private void Create(bool renderTarget) { var vkFormat = VulkanHelper.GetVKFormat(format); var usage = SharpVulkan.ImageUsageFlags.TransferSource | SharpVulkan.ImageUsageFlags.TransferDestination | SharpVulkan.ImageUsageFlags.Sampled; if (renderTarget) { usage |= SharpVulkan.ImageUsageFlags.ColorAttachment; } var tiling = SharpVulkan.ImageTiling.Optimal; var imageCreateInfo = new SharpVulkan.ImageCreateInfo { StructureType = SharpVulkan.StructureType.ImageCreateInfo, ImageType = SharpVulkan.ImageType.Image2D, Usage = usage, Format = vkFormat, Extent = new SharpVulkan.Extent3D((uint)width, (uint)height, 1), MipLevels = (uint)levelCount, ArrayLayers = 1, Samples = SharpVulkan.SampleCountFlags.Sample1, SharingMode = SharpVulkan.SharingMode.Exclusive, InitialLayout = SharpVulkan.ImageLayout.Undefined, Tiling = tiling }; image = context.Device.CreateImage(ref imageCreateInfo); var memoryPropertyFlags = SharpVulkan.MemoryPropertyFlags.DeviceLocal; if (IsPvrtc1Format(Format)) { memoryPropertyFlags |= SharpVulkan.MemoryPropertyFlags.HostVisible | SharpVulkan.MemoryPropertyFlags.HostCoherent; } memory = context.MemoryAllocator.Allocate(image, memoryPropertyFlags, tiling); var viewCreateInfo = new SharpVulkan.ImageViewCreateInfo { StructureType = SharpVulkan.StructureType.ImageViewCreateInfo, ViewType = SharpVulkan.ImageViewType.Image2D, Image = image, Format = vkFormat, Components = SharpVulkan.ComponentMapping.Identity, SubresourceRange = new SharpVulkan.ImageSubresourceRange(SharpVulkan.ImageAspectFlags.Color) }; imageView = context.Device.CreateImageView(ref viewCreateInfo); var memoryBarrier = new SharpVulkan.ImageMemoryBarrier { StructureType = SharpVulkan.StructureType.ImageMemoryBarrier, Image = image, OldLayout = SharpVulkan.ImageLayout.Undefined, NewLayout = SharpVulkan.ImageLayout.ShaderReadOnlyOptimal, SourceAccessMask = SharpVulkan.AccessFlags.None, DestinationAccessMask = SharpVulkan.AccessFlags.ShaderRead, SubresourceRange = new SharpVulkan.ImageSubresourceRange(SharpVulkan.ImageAspectFlags.Color) }; context.EndRenderPass(); context.EnsureCommandBuffer(); context.CommandBuffer.PipelineBarrier( SharpVulkan.PipelineStageFlags.TopOfPipe, SharpVulkan.PipelineStageFlags.VertexShader | SharpVulkan.PipelineStageFlags.FragmentShader, SharpVulkan.DependencyFlags.None, 0, null, 0, null, 1, &memoryBarrier); }