mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
4 changed files with 768360 additions and 0 deletions
|
|
@ -0,0 +1,46 @@
|
|||
namespace Brutal.VulkanApi.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Struct containing information about a memory allocation. Intentionally made similar to VMA's AllocationInfo
|
||||
/// </summary>
|
||||
/// <param name="Allocator">Allocator that sourced this allocation</param>
|
||||
/// <param name="Memory">Device memory handle</param>
|
||||
/// <param name="AllocSize">Size available in the memory allocation (might be more than requested)</param>
|
||||
/// <param name="AllocOffset">Offset into the memory allocation</param>
|
||||
/// <param name="MemoryTypeIndex">Memory type this allocation was made from</param>
|
||||
/// <param name="AllocHandle">Custom handle, optionally used by allocator</param>
|
||||
public readonly record struct AllocationInfo(
|
||||
IAllocator Allocator,
|
||||
VkDeviceMemory Memory,
|
||||
ByteSize AllocSize,
|
||||
ByteSize AllocOffset,
|
||||
int MemoryTypeIndex,
|
||||
nint AllocHandle
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
/// Struct containing information about a memory allocation. Intentionally made similar to VMA's AllocationCreateInfo
|
||||
/// </summary>
|
||||
/// <param name="Preference">Memory location preference can just leave as 'None'</param>
|
||||
/// <param name="RequiredProperties">Flags that must be set in a Memory Type chosen for an allocation</param>
|
||||
/// <param name="PreferredProperties">Flags that preferably should be set in a memory type chosen for an allocation</param>
|
||||
/// <param name="Priority">A floating-point value between 0 and 1, indicating the priority of the allocation relative to other memory allocations</param>
|
||||
/// <param name="Next">For advanced use only. A pointer to an application-defined structure that can be used to pass custom data to the allocator</param>
|
||||
public record struct CreateInfo(
|
||||
MemoryPreference Preference,
|
||||
VkMemoryPropertyFlags RequiredProperties,
|
||||
VkMemoryPropertyFlags PreferredProperties,
|
||||
float Priority,
|
||||
Ptr Next
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum listing memory allocation preferences: whether to prefer GPU or CPU memory
|
||||
/// </summary>
|
||||
public enum MemoryPreference : byte
|
||||
{
|
||||
None,
|
||||
PreferGpu,
|
||||
PreferCpu,
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
namespace Brutal.VulkanApi.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Base interface for a Vulkan allocator
|
||||
/// </summary>
|
||||
public interface IAllocator
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the Vulkan device this allocator is associated with
|
||||
/// </summary>
|
||||
/// <returns>Vulkan device handle</returns>
|
||||
Device GetDevice();
|
||||
|
||||
VkAllocator? VkAllocator { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Safely maps memory (allocated by this allocator) to a pointer.
|
||||
/// </summary>
|
||||
/// <param name="allocationMapInfo">Allocation info for memory</param>
|
||||
/// <returns>Pointer to mapped memory</returns>
|
||||
Ptr MapMemory(in AllocationMapInfo allocationMapInfo);
|
||||
|
||||
/// <summary>
|
||||
/// Safely unmaps memory (allocated by this allocator) from a pointer
|
||||
/// </summary>
|
||||
/// <param name="allocationMapInfo">Allocation info for memory</param>
|
||||
void UnmapMemory(in AllocationMapInfo allocationMapInfo);
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
namespace Brutal.VulkanApi.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Struct containing information about a buffer allocation
|
||||
/// </summary>
|
||||
/// <param name="VkBuffer">Handle to the Vulkan buffer</param>
|
||||
/// <param name="BufferOffset">Offset within the buffer where this allocation starts</param>
|
||||
/// <param name="BufferSize">Size of the allocation within the buffer</param>
|
||||
/// <param name="Usage">Usage flags this buffer supports, for reference</param>
|
||||
/// <param name="AllocationInfo">The internal memory allocation</param>
|
||||
public readonly record struct BufferAllocationInfo(
|
||||
VkBuffer VkBuffer,
|
||||
ByteSize BufferOffset,
|
||||
ByteSize BufferSize,
|
||||
VkBufferUsageFlags Usage,
|
||||
AllocationInfo AllocationInfo
|
||||
) : IMappable
|
||||
{
|
||||
ByteSize IMappable.MapSize => BufferSize;
|
||||
ByteSize IMappable.MapOffset => BufferOffset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for a buffer allocator object capable of allocating and freeing buffers
|
||||
/// </summary>
|
||||
public interface IBufferAllocator : IAllocator
|
||||
{
|
||||
/// <summary>
|
||||
/// Allocate a buffer with the given creation and allocation info
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="bufferCreateInfo">Vulkan buffer creation info</param>
|
||||
/// <param name="allocateCreateInfo">Memory allocation info</param>
|
||||
/// <returns>Struct containing all relevant information about allocation</returns>
|
||||
public BufferAllocationInfo AllocateBuffer(
|
||||
in string name,
|
||||
in VkBufferCreateInfo bufferCreateInfo,
|
||||
in AllocationInfo.CreateInfo allocateCreateInfo
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Free buffer allocation
|
||||
/// </summary>
|
||||
/// <param name="inAllocation">Allocation info for the buffer previously sourced from this allocator</param>
|
||||
public void FreeAllocation(in BufferAllocationInfo inAllocation);
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
namespace Brutal.VulkanApi.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Struct containing information about an image allocation
|
||||
/// </summary>
|
||||
public struct ImageAllocationInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Image handle
|
||||
/// </summary>
|
||||
public VkImage Image;
|
||||
|
||||
/// <summary>
|
||||
/// Size of image
|
||||
/// </summary>
|
||||
public VkExtent3D Extent;
|
||||
|
||||
/// <summary>
|
||||
/// Format of image, for reference
|
||||
/// </summary>
|
||||
public VkFormat Format;
|
||||
|
||||
/// <summary>
|
||||
/// Number of mip levels
|
||||
/// </summary>
|
||||
public int MipLevels;
|
||||
|
||||
/// <summary>
|
||||
/// Number of array layers allocated
|
||||
/// </summary>
|
||||
public int ArrayLayers;
|
||||
|
||||
/// <summary>
|
||||
/// Memory allocation info
|
||||
/// </summary>
|
||||
public AllocationInfo MemAllocationInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Allocator-specific handle
|
||||
/// </summary>
|
||||
public nint AllocHandle => MemAllocationInfo.AllocHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Allocator that sourced this image
|
||||
/// </summary>
|
||||
public IImageAllocator Allocator => (IImageAllocator)MemAllocationInfo.Allocator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for an image allocator object capable of allocating and freeing images
|
||||
/// </summary>
|
||||
public interface IImageAllocator : IAllocator
|
||||
{
|
||||
/// <summary>
|
||||
/// Allocate an image with the given creation and allocation info.
|
||||
/// </summary>
|
||||
/// <param name="name">Debug name of allocation</param>
|
||||
/// <param name="imageCreateInfo">Vulkan image creation info</param>
|
||||
/// <param name="allocateCreateInfo">Memory allocation info</param>
|
||||
/// <returns>Struct containing all relevant information about the allocation</returns>
|
||||
public ImageAllocationInfo AllocateImage(
|
||||
in string name,
|
||||
in VkImageCreateInfo imageCreateInfo,
|
||||
in AllocationInfo.CreateInfo allocateCreateInfo
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Free an image allocation
|
||||
/// </summary>
|
||||
/// <param name="inAllocation">Struct containing all relevant information about the allocation</param>
|
||||
public void FreeAllocation(in ImageAllocationInfo inAllocation);
|
||||
}
|
||||
Loading…
Reference in a new issue