271 lines
5.3 KiB
C
271 lines
5.3 KiB
C
#ifndef PIPELINE_H
|
|
#define PIPELINE_H
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
#include "cglm/types.h"
|
|
#include "vk_mem_alloc.h"
|
|
#include "gpu.h"
|
|
|
|
#include "ft2build.h"
|
|
#include FT_FREETYPE_H
|
|
|
|
#define ANCHOR_TOP_LEFT 0
|
|
#define ANCHOR_TOP_RIGHT 1
|
|
#define ANCHOR_BOTTOM_LEFT 2
|
|
#define ANCHOR_BOTTOM_RIGHT 3
|
|
#define ANCHOR_CENTER 4
|
|
|
|
typedef struct ComputePipelineStruct {
|
|
VkPipelineLayout layout;
|
|
VkPipeline pipeline;
|
|
} ComputePipeline;
|
|
|
|
typedef struct GraphicsPipelineStruct {
|
|
VkPipelineLayout layout;
|
|
VkPipeline pipeline;
|
|
} GraphicsPipeline;
|
|
|
|
typedef struct DrawCommandStruct {
|
|
uint32_t vertex_count;
|
|
uint32_t instance_count;
|
|
uint32_t first_vertex;
|
|
uint32_t first_instance;
|
|
} DrawCommand;
|
|
|
|
typedef struct DispatchCommandStruct {
|
|
uint32_t x;
|
|
uint32_t y;
|
|
uint32_t z;
|
|
} DispatchCommand;
|
|
|
|
typedef struct UIPushConstantStruct {
|
|
VkDeviceAddress layer;
|
|
float time;
|
|
uint32_t pad;
|
|
} UIPushConstant;
|
|
|
|
typedef struct GPUFontStruct {
|
|
VkDeviceAddress symbol_list;
|
|
uint32_t num_symbols;
|
|
uint32_t width;
|
|
uint32_t height;
|
|
} GPUFont;
|
|
|
|
typedef struct GPUSymbolStruct {
|
|
float top;
|
|
float left;
|
|
float width;
|
|
float height;
|
|
vec2 advance;
|
|
} GPUSymbol;
|
|
|
|
typedef struct FontStruct {
|
|
VmaAllocation symbol_memory;
|
|
VmaAllocation image_memory;
|
|
VkBuffer symbols;
|
|
VkImage image;
|
|
VkImageView view;
|
|
VkSampler sampler;
|
|
uint32_t* charmap;
|
|
uint32_t num_symbols;
|
|
uint32_t index;
|
|
char* family;
|
|
char* style;
|
|
} Font;
|
|
|
|
typedef struct TextureStruct {
|
|
VmaAllocation image_memory;
|
|
VkImage image;
|
|
VkImageView view;
|
|
VkSampler sampler;
|
|
|
|
char* path;
|
|
} Texture;
|
|
|
|
typedef struct GPUStringStruct {
|
|
vec2 pos;
|
|
vec4 color;
|
|
float size;
|
|
uint32_t offset;
|
|
uint32_t length;
|
|
uint32_t font;
|
|
uint32_t id;
|
|
} GPUString;
|
|
|
|
typedef struct GPUDrawableStruct {
|
|
vec2 pos;
|
|
vec2 size;
|
|
vec4 color;
|
|
uint32_t type;
|
|
uint32_t var1;
|
|
uint32_t var2;
|
|
float var3;
|
|
float var4;
|
|
uint32_t id;
|
|
} GPUDrawable;
|
|
|
|
typedef struct GPULayerStruct {
|
|
DrawCommand draw;
|
|
DispatchCommand dispatch_strings;
|
|
|
|
uint32_t max_drawables;
|
|
uint32_t max_codes;
|
|
uint32_t max_strings;
|
|
uint32_t num_drawables;
|
|
|
|
VkDeviceAddress strings;
|
|
VkDeviceAddress codes;
|
|
VkDeviceAddress drawables;
|
|
VkDeviceAddress container;
|
|
} GPULayer;
|
|
|
|
typedef struct LayerStruct {
|
|
VkBuffer strings[MAX_FRAMES_IN_FLIGHT];
|
|
VkBuffer codes[MAX_FRAMES_IN_FLIGHT];
|
|
VkBuffer drawables[MAX_FRAMES_IN_FLIGHT];
|
|
VkBuffer layer[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VmaAllocation strings_memory[MAX_FRAMES_IN_FLIGHT];
|
|
VmaAllocation drawables_memory[MAX_FRAMES_IN_FLIGHT];
|
|
VmaAllocation codes_memory[MAX_FRAMES_IN_FLIGHT];
|
|
VmaAllocation layer_memory[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
GPUDrawable* drawables_buffer;
|
|
GPUString* strings_buffer;
|
|
uint32_t* codes_buffer;
|
|
|
|
GPULayer data;
|
|
} Layer;
|
|
|
|
typedef struct LayerInputStruct {
|
|
uint32_t num_strings;
|
|
uint32_t num_codes;
|
|
uint32_t num_drawables;
|
|
|
|
uint32_t max_codes;
|
|
uint32_t max_strings;
|
|
uint32_t max_drawables;
|
|
|
|
GPUString* strings;
|
|
uint32_t* codes;
|
|
GPUDrawable* drawables;
|
|
} LayerInput;
|
|
|
|
typedef struct GPUContainerStruct {
|
|
vec2 offset;
|
|
vec2 size;
|
|
uint32_t anchor;
|
|
|
|
VkDeviceAddress context;
|
|
} GPUContainer;
|
|
|
|
typedef struct ContainerStruct {
|
|
VkBuffer container[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VmaAllocation container_memory[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
VkDeviceAddress address[MAX_FRAMES_IN_FLIGHT];
|
|
|
|
GPUContainer data;
|
|
|
|
uint32_t id;
|
|
uint32_t layer_count;
|
|
Layer* layers;
|
|
} Container;
|
|
|
|
typedef struct ContainerInputStruct {
|
|
uint32_t id;
|
|
uint32_t anchor;
|
|
vec2 offset;
|
|
vec2 size;
|
|
|
|
uint32_t layer_count;
|
|
LayerInput* layers;
|
|
} ContainerInput;
|
|
|
|
typedef struct GPUUIContextStruct {
|
|
VkDeviceAddress font_infos;
|
|
vec2 screen;
|
|
vec2 extent;
|
|
vec2 scale;
|
|
} GPUUIContext;
|
|
|
|
typedef struct UIContext {
|
|
VkDeviceAddress address;
|
|
|
|
VkBuffer context;
|
|
|
|
VmaAllocation context_memory;
|
|
|
|
VkBuffer font_infos;
|
|
VmaAllocation font_infos_memory;
|
|
|
|
VkDescriptorSet textures;
|
|
VkDescriptorSet samplers;
|
|
VkDescriptorSet font_samplers;
|
|
VkDescriptorSet font_textures;
|
|
VkDescriptorSetLayout samplers_layout;
|
|
VkDescriptorSetLayout textures_layout;
|
|
VkDescriptorPool fonts_pool;
|
|
VkDescriptorPool textures_pool;
|
|
|
|
GraphicsPipeline pipeline;
|
|
ComputePipeline string_pipeline;
|
|
|
|
uint32_t max_fonts;
|
|
uint32_t max_textures;
|
|
|
|
Font* fonts;
|
|
Texture* texture_slots;
|
|
|
|
uint32_t max_containers;
|
|
Container* containers;
|
|
|
|
GPUUIContext data;
|
|
|
|
FT_Library freetype;
|
|
} UIContext;
|
|
|
|
VkResult create_ui_context(
|
|
uint32_t max_fonts,
|
|
uint32_t max_textures,
|
|
uint32_t max_containers,
|
|
RenderContext* gpu,
|
|
UIContext* context);
|
|
|
|
VkResult load_font(
|
|
uint32_t index,
|
|
const char* ttf_file,
|
|
uint32_t size,
|
|
VkBool32 antialias,
|
|
RenderContext* gpu,
|
|
UIContext* context);
|
|
|
|
VkResult load_texture(
|
|
const char* png_path,
|
|
RenderContext* gpu,
|
|
UIContext* context,
|
|
uint32_t* index);
|
|
|
|
VkResult create_container(
|
|
ContainerInput* container,
|
|
RenderContext* gpu,
|
|
UIContext* context);
|
|
|
|
VkResult create_layer(
|
|
uint32_t index,
|
|
LayerInput* input,
|
|
RenderContext* gpu,
|
|
Container* container);
|
|
|
|
VkResult map_string(
|
|
const char * text,
|
|
uint32_t* buffer,
|
|
uint32_t offset,
|
|
uint32_t font,
|
|
UIContext* context);
|
|
|
|
#endif
|