mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-31 08:41:11 +00:00
[vulkan] Add a mini resource subsystem
The resource subsystem creates buffers, images, buffer views and image views in a single batch operation, using a single memory object to back all the buffers and images. I had been doing this by hand for a while, but got tired of jumping through all those vulkan hoops. While it's still a little tedious to set up the arrays for QFV_CreateResource (and they need to be kept around for QFV_DestroyResource), it really eases calculation of memory object size and sub-resource offsets. And destroying all the objects is just one call to QFV_DestroyResource.
This commit is contained in:
parent
9d7cad420d
commit
a4f500da3c
3 changed files with 340 additions and 0 deletions
68
include/QF/Vulkan/resource.h
Normal file
68
include/QF/Vulkan/resource.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef __QF_Vulkan_resource_h
|
||||
#define __QF_Vulkan_resource_h
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
#define VK_NO_PROTOTYPES
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
typedef enum {
|
||||
qfv_res_buffer = 1,
|
||||
qfv_res_buffer_view,
|
||||
qfv_res_image,
|
||||
qfv_res_image_view,
|
||||
} qfv_res_type;
|
||||
|
||||
typedef struct qfv_resobj_s {
|
||||
const char *name;
|
||||
qfv_res_type type;
|
||||
union {
|
||||
struct {
|
||||
VkDeviceSize size;
|
||||
VkBufferUsageFlags usage;
|
||||
VkBuffer buffer;
|
||||
} buffer;
|
||||
struct {
|
||||
unsigned buffer;
|
||||
VkFormat format;
|
||||
VkDeviceSize offset;
|
||||
VkDeviceSize size;
|
||||
VkBufferView view;
|
||||
} buffer_view;
|
||||
struct {
|
||||
int cubemap;
|
||||
VkImageType type;
|
||||
VkFormat format;
|
||||
VkExtent3D extent;
|
||||
uint32_t num_mipmaps;
|
||||
uint32_t num_layers;
|
||||
VkSampleCountFlags samples;
|
||||
VkImageUsageFlags usage;
|
||||
VkImage image;
|
||||
} image;
|
||||
struct {
|
||||
unsigned image;
|
||||
VkImageViewType type;
|
||||
VkFormat format;
|
||||
VkImageAspectFlags aspect;
|
||||
VkImageView view;
|
||||
} image_view;
|
||||
};
|
||||
} qfv_resobj_t;
|
||||
|
||||
typedef struct qfv_resource_s {
|
||||
const char *name;
|
||||
struct va_ctx_s *va_ctx;
|
||||
VkMemoryPropertyFlags memory_properties;
|
||||
unsigned num_objects;
|
||||
qfv_resobj_t *objects;
|
||||
VkDeviceMemory memory;
|
||||
} qfv_resource_t;
|
||||
|
||||
struct qfv_device_s;
|
||||
|
||||
int QFV_CreateResource (struct qfv_device_s *device, qfv_resource_t *resource);
|
||||
void QFV_DestroyResource (struct qfv_device_s *device,
|
||||
qfv_resource_t *resource);
|
||||
|
||||
#endif//__QF_Vulkan_resource_h
|
Loading…
Add table
Add a link
Reference in a new issue