spacegame/include/gpu_mem.h

57 lines
1.6 KiB
C

#ifndef GPU_MEM_H
#define GPU_MEM_H
#include <vulkan/vulkan_core.h>
#include <stdio.h>
2024-01-12 19:40:21 -07:00
#include <stdbool.h>
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;
2024-01-12 19:40:21 -07:00
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