namespace Brutal.VulkanApi.Abstractions; /// /// Allocation information for a partition of an image allocation (portion of a larger image) /// /// Handle to the source image view /// Number of array layers allocated to this sub-image, within ImageViewSubresourceRange /// Array offset of the sub-image, within ImageViewSubresourceRange /// Size of the sub-image /// Offset of the sub-image within the original image /// Source object that created this partition, if any. If null, assume this is a full image allocation public readonly record struct ImageViewPartitionInfo( ImageViewEx ImageView, int ArrayCount, int ArrayOffset, VkExtent3D Extent, VkOffset3D Offset, IImageViewPartitioner? Partitioner ) { /// /// Creation information for a sub-image allocation /// /// Size of the sub-image /// Number of array layers allocated to this sub-image, within ImageViewSubresourceRange public record struct CreateInfo(VkExtent3D Extent, int LayerCount); /// /// If true, this partition is a full image allocation /// public bool IsFullPartition => Partitioner is null; public ImageEx Image => ImageView.Image; /// /// Image handle /// public VkImage VkImage => Image.VkImage; /// /// Subresource range of the actual sub-image, within the original image /// public VkImageSubresourceRange LocalSubresourceRange => ImageView.SubresourceRange with { BaseArrayLayer = ImageView.SubresourceRange.BaseArrayLayer + ArrayOffset, LayerCount = ArrayCount, }; /// /// Return this partition to the recycling partitioner that created it, via /// . For a full partition or a /// non-recycling partitioner this is a no-op - the backing view and image belong to their /// owner and are released by disposing them directly. /// public void Free() { if (Partitioner is IRecycleImageViewPartitioner recycler) recycler.FreePartition(in this); } /// /// Get the normalized offset of the sub-image within the original image. /// EG: for UV mapping /// /// Normalized offset as float3 public readonly float3 GetNormalizedOffset() { var totalExtent = Image.Extent; return new float3( Offset.X / (float)totalExtent.Width, Offset.Y / (float)totalExtent.Height, Offset.Z / (float)totalExtent.Depth ); } /// /// Get the normalized extent of the sub-image within the original image /// EG: for UV mapping /// /// Normalized extent as float3 public readonly float3 GetNormalizedExtent() { var totalExtent = Image.Extent; return new float3( Extent.Width / (float)totalExtent.Width, Extent.Height / (float)totalExtent.Height, Extent.Depth / (float)totalExtent.Depth ); } }