ULRE/example/Vulkan/VKDevice.h

96 lines
3.4 KiB
C
Raw Normal View History

#ifndef HGL_GRAPH_RENDER_SURFACE_INCLUDE
#define HGL_GRAPH_RENDER_SURFACE_INCLUDE
#include<hgl/type/List.h>
#include"VK.h"
#include"Window.h"
2019-04-18 16:06:44 +08:00
#include"VKDeviceAttribute.h"
#include"VKFramebuffer.h"
VK_NAMESPACE_BEGIN
2019-04-18 22:10:24 +08:00
struct PhysicalDevice;
class Buffer;
class VertexBuffer;
class CommandBuffer;
class RenderPass;
2019-04-19 19:58:01 +08:00
class Fence;
2019-04-19 20:04:08 +08:00
class Semaphore;
2019-04-20 16:12:22 +08:00
#define MAX_FRAMES_IN_FLIGHT 2
2019-04-18 16:06:44 +08:00
class Device
{
2019-04-18 22:24:39 +08:00
DeviceAttribute *attr;
2019-04-19 20:10:59 +08:00
Semaphore *image_acquired_semaphore;
2019-04-20 16:12:22 +08:00
Fence *draw_fence;
RenderPass *main_rp;
ObjectList<Framebuffer> main_fb;
2019-04-20 16:12:22 +08:00
uint32_t current_frame;
2019-04-19 20:10:59 +08:00
VkPresentInfoKHR present;
private:
2019-04-18 16:06:44 +08:00
friend Device *CreateRenderDevice(VkInstance,const PhysicalDevice *,Window *);
2019-04-19 20:10:59 +08:00
Device(DeviceAttribute *da);
public:
2019-04-18 22:24:39 +08:00
virtual ~Device();
2019-04-23 00:37:45 +08:00
operator VkDevice () {return attr->device;}
2019-04-18 22:24:39 +08:00
VkSurfaceKHR GetSurface () {return attr->surface;}
VkDevice GetDevice () {return attr->device;}
const PhysicalDevice *GetPhysicalDevice ()const {return attr->physical_device;}
const VkExtent2D & GetExtent ()const {return attr->swapchain_extent;}
VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;}
2019-04-19 20:40:04 +08:00
VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;}
2019-04-20 02:28:57 +08:00
public:
2019-04-20 16:12:22 +08:00
const uint32_t GetSwapChainImageCount ()const {return attr->sc_image_views.GetCount();}
ImageView *GetColorImageView (int index) {return attr->sc_image_views[index];}
ImageView *GetDepthImageView () {return attr->depth.view;}
2019-04-20 16:12:22 +08:00
const uint32_t GetCurrentFrameIndices () {return current_frame;}
2019-04-20 02:28:57 +08:00
RenderPass * GetRenderPass () {return main_rp;}
Framebuffer * GetFramebuffer (int index) {return main_fb[index];}
public:
Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);
VertexBuffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkFormat format,uint32_t count,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);
2019-04-18 22:10:24 +08:00
#define CREATE_FORMAT_BUFFER_OBJECT(LargeName,type) VertexBuffer *Create##LargeName(VkFormat format,uint32_t count,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,format,count,sharing_mode);}
CREATE_FORMAT_BUFFER_OBJECT(VBO,VERTEX)
CREATE_FORMAT_BUFFER_OBJECT(IBO,INDEX)
#undef CREATE_FORMAT_BUFFER_OBJECT
#define CREATE_BUFFER_OBJECT(LargeName,type) Buffer *Create##LargeName(VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size,sharing_mode);}
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
2019-04-19 21:14:56 +08:00
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
CREATE_BUFFER_OBJECT(INBO,INDIRECT)
#undef CREATE_BUFFER_OBJECT
CommandBuffer * CreateCommandBuffer();
RenderPass * CreateRenderPass(VkFormat color_format,VkFormat depth_format);
Fence * CreateFence();
Semaphore * CreateSem();
bool AcquireNextImage ();
2019-04-20 16:12:22 +08:00
bool QueueSubmit (CommandBuffer *);
bool Wait (bool wait_all=VK_TRUE,uint64_t time_out=HGL_NANO_SEC_PER_SEC*0.1);
bool QueuePresent ();
2019-04-18 16:06:44 +08:00
};//class Device
VK_NAMESPACE_END
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE