public static Vk.Format FindDepthFormat(VkContext state) => FindSupportedFormat(state, new Vk.Format[] { Vk.Format.D32Sfloat, Vk.Format.D32SfloatS8Uint, Vk.Format.D24UnormS8Uint }, Vk.ImageTiling.Optimal, Vk.FormatFeatureFlags.DepthStencilAttachment);
public static BufferWithMemory CreateBuffer(VkContext vulkan, Vk.DeviceSize size, Vk.BufferUsageFlags usage, Vk.MemoryPropertyFlags memoryProps, Vk.SharingMode sharingMode) { var bufferInfo = new Vk.BufferCreateInfo(); bufferInfo.Size = size; bufferInfo.Usage = usage; bufferInfo.SharingMode = sharingMode; var container = new BufferWithMemory(); container.Buffer = vulkan.Device.CreateBuffer(bufferInfo); var memoryReqs = vulkan.Device.GetBufferMemoryRequirements(container.Buffer); var allocInfo = new Vk.MemoryAllocateInfo(); allocInfo.AllocationSize = memoryReqs.Size; allocInfo.MemoryTypeIndex = FindMemoryType(memoryReqs.MemoryTypeBits, vulkan.PhysicalDevice, memoryProps); container.Memory = vulkan.Device.AllocateMemory(allocInfo); container.Bind(vulkan.Device, 0); return(container); }
public static void CopyBuffer(Vk.Buffer src, Vk.Buffer dest, Vk.DeviceSize size, VkContext state) { var commandBuffer = state.BeginSingleTimeCommands(state.TransferCommandPool); var copyRegion = new Vk.BufferCopy(); copyRegion.SrcOffset = 0; copyRegion.DstOffset = 0; copyRegion.Size = size; commandBuffer.CmdCopyBuffer(src, dest, copyRegion); state.EndSingleTimeCommands(state.TransferQueue, state.TransferCommandPool, commandBuffer); }
public static Vk.Format FindSupportedFormat(VkContext state, IEnumerable <Vk.Format> candidates, Vk.ImageTiling tiling, Vk.FormatFeatureFlags features) { foreach (Vk.Format format in candidates) { var props = state.PhysicalDevice.GetFormatProperties(format); if (tiling == Vk.ImageTiling.Linear && (props.LinearTilingFeatures & features) != 0) { return(format); } else if (tiling == Vk.ImageTiling.Optimal && (props.OptimalTilingFeatures & features) != 0) { return(format); } } throw new System.Exception("Failed to find a supported format."); }
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)); }
public static ImageWithMemory CreateImage(VkContext state, uint width, uint height, Vk.Format format, Vk.ImageTiling tiling, Vk.ImageUsageFlags usageFlags, Vk.MemoryPropertyFlags props) { var extent = new Vk.Extent3D(); extent.Width = width; extent.Height = height; extent.Depth = 1; var imageInfo = new Vk.ImageCreateInfo(); imageInfo.ImageType = Vk.ImageType.Image2D; imageInfo.Extent = extent; imageInfo.MipLevels = 1; imageInfo.ArrayLayers = 1; imageInfo.Format = format; imageInfo.Tiling = tiling; imageInfo.InitialLayout = Vk.ImageLayout.Undefined; imageInfo.Usage = usageFlags; imageInfo.Samples = Vk.SampleCountFlags.Count1; imageInfo.SharingMode = Vk.SharingMode.Exclusive; var image = new ImageWithMemory(); image.Image = state.Device.CreateImage(imageInfo); var memoryReqs = state.Device.GetImageMemoryRequirements(image.Image); var allocInfo = new Vk.MemoryAllocateInfo(); allocInfo.AllocationSize = memoryReqs.Size; allocInfo.MemoryTypeIndex = FindMemoryType(memoryReqs.MemoryTypeBits, state.PhysicalDevice, props); image.Memory = state.Device.AllocateMemory(allocInfo); image.Bind(state.Device, 0); return(image); }