#ifndef GPU_MEM_H #define GPU_MEM_H #include #include #include typedef struct GPUMemoryTypeStruct { VkMemoryPropertyFlags flags; uint32_t index; } GPUMemoryType; typedef struct GPUMemoryChunkStruct { VkDeviceSize size; VkDeviceSize offset; struct GPUMemoryChunkStruct* next; } GPUMemoryChunk; typedef struct GPUPageStruct { VkDeviceMemory memory; VkDeviceSize size; GPUMemoryType type; GPUMemoryChunk* free; GPUMemoryChunk* allocated; void* ptr; } GPUPage; typedef struct GPUBufferStruct { GPUPage* page; GPUMemoryChunk* memory; VkBuffer handle; } GPUBuffer; typedef struct GPUImageStruct { GPUPage* page; GPUMemoryChunk* memory; VkImage handle; } GPUImage; GPUMemoryType pick_memory(VkPhysicalDeviceMemoryProperties memories, uint32_t filter, VkMemoryPropertyFlags include, VkMemoryPropertyFlags exclude); VkResult gpu_page_allocate(VkDevice device, VkPhysicalDeviceMemoryProperties memories, VkDeviceSize size, uint32_t filter, VkMemoryPropertyFlags include, VkMemoryPropertyFlags exclude, GPUPage** handle); void gpu_page_free(VkDevice device, GPUPage* page); VkResult gpu_buffer_malloc(VkDevice device, GPUPage* page, VkDeviceSize size, VkBufferUsageFlags usage, GPUBuffer* buffer); VkResult gpu_image_malloc(VkDevice device, GPUPage* page, VkImageCreateInfo* info, GPUImage* image); void gpu_buffer_free(VkDevice device, GPUBuffer buffer); void gpu_free(GPUPage* page, GPUMemoryChunk* memory); void fprintchunks(FILE* out, GPUMemoryChunk* start); #endif