vulkan游戏引擎核心vulkan_types.inl实现

1.vulkan_types.inl

#pragma once

#include "defines.h"

#include "core/asserts.h"

#include "renderer/renderer_types.inl"

#include <vulkan/vulkan.h>

#define VK_CHECK(expr) \

{ \

KASSERT(expr == VK_SUCCESS); \

}

typedef struct vulkan_buffer{

u64 total_size;

VkBuffer handle;

VkBufferUsageFlagBits usage;

b8 is_locked;

VkDeviceMemory memory;

i32 memory_index;

u32 memory_property_flags;

}vulkan_buffer;

typedef struct vulkan_swapchain_support_info{

VkSurfaceCapabilitiesKHR capabilities;

u32 format_count;

VkSurfaceFormatKHR* formats;

u32 present_mode_count;

VkPresentModeKHR* present_modes;

}vulkan_swapchain_support_info;

typedef struct vulkan_device{

VkPhysicalDevice physical_device;

VkDevice logical_device;

vulkan_swapchain_support_info swapchain_support;

i32 graphics_queue_index;

i32 present_queue_index;

i32 transfer_queue_index;

VkQueue graphics_queue;

VkQueue present_queue;

VkQueue transfer_queue;

VkCommandPool graphics_command_pool;

VkPhysicalDeviceProperties properties;

VkPhysicalDeviceFeatures features;

VkPhysicalDeviceMemoryProperties memory;

VkFormat depth_format;

}vulkan_device;

typedef struct vulkan_image{

VkImage handle;

VkDeviceMemory memory;

VkImageView view;

u32 width;

u32 height;

}vulkan_image;

typedef enum vulkan_render_pass_state{

READY,

RECORDING,

IN_RENDER_PASS,

RECORDING_ENDED,

SUBMITTED,

NOT_ALLOCATED

}vulkan_render_pass_state;

typedef struct vulkan_renderpass{

VkRenderPass handle;

f32 x,y,w,h;

f32 r,g,b,a;

f32 depth;

u32 stencil;

vulkan_render_pass_state state;

}vulkan_renderpass;

typedef struct vulkan_framebuffer{

VkFramebuffer handle;

u32 attachment_count;

VkImageView* attachments;

vulkan_renderpass* renderpass;

}vulkan_framebuffer;

typedef struct vulkan_swapchain{

VkSurfaceFormatKHR image_format;

u8 max_frames_in_flight;

VkSwapchainKHR handle;

u32 image_count;

VkImage* images;

VkImageView* views;

vulkan_image depth_attachment;

//framebuffers used for on-screen rendering

vulkan_framebuffer* framebuffers;

}vulkan_swapchain;

typedef enum vulkan_command_buffer_state{

COMMAND_BUFFER_STATE_READY,

COMMAND_BUFFER_STATE_RECORDING,

COMMAND_BUFFER_STATE_IN_RENDER_PASS,

COMMAND_BUFFER_STATE_RECORDING_ENDED,

COMMAND_BUFFER_STATE_SUBMITTED,

COMMAND_BUFFER_STATE_NOT_ALLOCATED

}vulkan_command_buffer_state;

typedef struct vulkan_command_buffer{

VkCommandBuffer handle;

vulkan_command_buffer_state state;

}vulkan_command_buffer;

typedef struct vulkan_shader_stage{

VkShaderModuleCreateInfo create_info;

VkShaderModule handle;

VkPipelineShaderStageCreateInfo shader_stage_create_info;

}vulkan_shader_stage;

typedef struct vulkan_pipeline{

VkPipeline handle;

VkPipelineLayout pipeline_layout;

}vulkan_pipeline;

#define OBJECT_SHADER_STAGE_COUNT 2

typedef struct vulkan_object_shader{

vulkan_shader_stage stages[OBJECT_SHADER_STAGE_COUNT];

VkDescriptorPool global_descriptor_pool;

VkDescriptorSetLayout global_descriptor_set_layout;

VkDescriptorSet global_descriptor_sets[3];

//b8 descriptor_updated[3];

global_uniform_object global_ubo;

vulkan_buffer global_uniform_buffer;

vulkan_pipeline pipeline;

}vulkan_object_shader;

typedef struct vulkan_fence{

VkFence handle;

b8 is_signaled;

}vulkan_fence;

typedef struct vulkan_context{

u32 framebuffer_width;

u32 framebuffer_height;

u64 framebuffer_size_generation;

u64 framebuffer_size_last_generation;

VkInstance instance;

VkAllocationCallbacks* allocator;

VkSurfaceKHR surface;

#if defined(_DEBUG)

VkDebugUtilsMessengerEXT debug_messenger;

//PFN_vkSetDebugUtilsObjectNameEXT pfnSetDebugUtilsObjectNameEXT;

/** @brief The function pointer to set free-form debug object tag data. */

#endif

vulkan_device device;

b8 validation_enabled;

vulkan_swapchain swapchain;

vulkan_renderpass main_renderpass;

vulkan_buffer object_vertex_buffer;

vulkan_buffer object_index_buffer;

//darray

vulkan_command_buffer* graphics_command_buffers;

//darray

VkSemaphore* image_available_semaphores;

//darray

VkSemaphore* queue_complete_semaphores;

u32 in_flight_fence_count;

vulkan_fence* in_flight_fences;

//Holds pointers to fences which exist and are owned elsewhere

vulkan_fence** images_in_flight;

u32 image_index;

u32 current_frame;

b8 recreating_swapchain;

vulkan_object_shader object_shader;

u64 geometry_vertex_offset;

u64 geometry_index_offset;

i32 (*find_memory_index)(u32 type_filter,u32 property_flags);

}vulkan_context;

typedef struct vulkan_texture_data{

vulkan_image image;

VkSampler sampler;

}vulkan_texture_data;

相关推荐
CXH7285 分钟前
从零开始创建 Vue 3 开发环境并构建第一个 Demo
前端·javascript·vue.js
qq2439201617 分钟前
搭建frp内网穿透
服务器·网络·运维开发
江沉晚呤时19 分钟前
深入了解 C# 异步编程库 AsyncEx
java·前端·数据库·c#·.netcore
有很多梦想要实现21 分钟前
Nest全栈到失业(四):半小时图书管理系统-Book
开发语言·前端·javascript·数据库·typescript·webstorm
疯狂的沙粒1 小时前
uniapp开发企业微信小程序时 wx.qy.login 在uniapp中使用的时候,需要导包吗?
前端·javascript·微信小程序·小程序·uni-app
hixiaoyang1 小时前
MVCC 原理与并发控制实现
运维·服务器·数据库
Allen Bright1 小时前
【HTML-15】HTML表单:构建交互式网页的基石
前端·html
小张快跑。1 小时前
<el-date-picker>配置禁用指定日期之前的时间选择(Vue2+Vue3)
前端·javascript·vue.js
_abab1 小时前
Nginx 基本概念深度解析:从服务器特性到代理模式应用
服务器·nginx·代理模式
geovindu2 小时前
vue3: tmap (腾讯地图)using typescript
前端·javascript·typescript