2019-05-07 12:46:25 +08:00
|
|
|
|
#ifndef HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
2019-04-10 21:54:39 +08:00
|
|
|
|
#define HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include<hgl/type/List.h>
|
2019-04-28 16:06:53 +08:00
|
|
|
|
#include<hgl/type/BaseString.h>
|
|
|
|
|
#include<hgl/type/Map.h>
|
2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/platform/Window.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VK.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
2019-07-13 02:37:19 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKSwapchain.h>
|
2019-07-16 19:59:53 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
2019-05-22 18:10:13 +08:00
|
|
|
|
#include<hgl/graph/VertexBufferCreater.h>
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-18 16:06:44 +08:00
|
|
|
|
class Device
|
2019-04-11 02:29:21 +08:00
|
|
|
|
{
|
2019-04-18 22:24:39 +08:00
|
|
|
|
DeviceAttribute *attr;
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2019-07-16 21:21:20 +08:00
|
|
|
|
SubmitQueue *textureSQ;
|
2019-05-21 00:22:18 +08:00
|
|
|
|
CommandBuffer *texture_cmd_buf;
|
2019-04-23 00:02:59 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
Swapchain *swapchain;
|
2019-07-16 19:59:53 +08:00
|
|
|
|
SwapchainRenderTarget *swapchainRT;
|
2019-05-07 12:46:25 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2019-07-15 22:37:00 +08:00
|
|
|
|
friend Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2019-04-19 20:10:59 +08:00
|
|
|
|
Device(DeviceAttribute *da);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2019-04-18 22:24:39 +08:00
|
|
|
|
virtual ~Device();
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
operator VkDevice () {return attr->device;}
|
2019-07-15 22:37:00 +08:00
|
|
|
|
DeviceAttribute * GetDeviceAttribute () {return attr;}
|
2019-04-23 00:37:45 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
VkSurfaceKHR GetSurface () {return attr->surface;}
|
|
|
|
|
VkDevice GetDevice () {return attr->device;}
|
|
|
|
|
const PhysicalDevice * GetPhysicalDevice ()const {return attr->physical_device;}
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
VkDescriptorPool GetDescriptorPool () {return attr->desc_pool;}
|
|
|
|
|
VkPipelineCache GetPipelineCache () {return attr->pipeline_cache;}
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
const VkFormat GetSurfaceFormat ()const {return attr->format;}
|
|
|
|
|
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
|
2019-04-20 02:28:57 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
Swapchain * GetSwapchain () {return swapchain;}
|
2019-04-20 16:12:22 +08:00
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
SwapchainRenderTarget * GetSwapchainRT () {return swapchainRT;}
|
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
public:
|
2019-04-23 00:02:59 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
bool Resize (const VkExtent2D &);
|
2019-07-16 10:26:24 +08:00
|
|
|
|
bool Resize (const uint32_t &w,const uint32_t &h)
|
|
|
|
|
{
|
|
|
|
|
VkExtent2D extent={w,h};
|
|
|
|
|
|
|
|
|
|
return Resize(extent);
|
|
|
|
|
}
|
2019-05-07 12:46:25 +08:00
|
|
|
|
|
2019-06-26 15:18:31 +08:00
|
|
|
|
public: //内存相关
|
|
|
|
|
|
|
|
|
|
Memory *Device::CreateMemory(const VkMemoryRequirements &,uint32_t properties);
|
|
|
|
|
|
2019-05-07 12:46:25 +08:00
|
|
|
|
public: //Buffer相关
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2019-04-25 14:33:50 +08:00
|
|
|
|
Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,const void *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);
|
|
|
|
|
Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(buf_usage,size,nullptr,sharing_mode);}
|
2019-05-05 14:22:58 +08:00
|
|
|
|
|
2019-04-25 14:33:50 +08:00
|
|
|
|
VertexBuffer * CreateVBO(VkFormat format,uint32_t count,const void *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);
|
|
|
|
|
VertexBuffer * CreateVBO(VkFormat format,uint32_t count,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateVBO(format,count,nullptr,sharing_mode);}
|
2019-05-22 18:10:13 +08:00
|
|
|
|
VertexBuffer * CreateVBO(const VertexBufferCreater *vbc,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateVBO(vbc->GetDataType(),vbc->GetCount(),vbc->GetData(),sharing_mode);}
|
2019-04-16 02:21:35 +08:00
|
|
|
|
|
2019-04-25 14:33:50 +08:00
|
|
|
|
IndexBuffer * CreateIBO(VkIndexType index_type,uint32_t count,const void *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);
|
2019-05-06 12:00:03 +08:00
|
|
|
|
IndexBuffer * CreateIBO16(uint32_t count,const uint16 *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateIBO(VK_INDEX_TYPE_UINT16,count,(void *)data,sharing_mode);}
|
|
|
|
|
IndexBuffer * CreateIBO32(uint32_t count,const uint32 *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateIBO(VK_INDEX_TYPE_UINT32,count,(void *)data,sharing_mode);}
|
2019-04-11 22:40:13 +08:00
|
|
|
|
|
2019-04-25 14:33:50 +08:00
|
|
|
|
IndexBuffer * CreateIBO(VkIndexType index_type,uint32_t count,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateIBO(index_type,count,nullptr,sharing_mode);}
|
|
|
|
|
IndexBuffer * CreateIBO16(uint32_t count,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateIBO(VK_INDEX_TYPE_UINT16,count,nullptr,sharing_mode);}
|
|
|
|
|
IndexBuffer * CreateIBO32(uint32_t count,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateIBO(VK_INDEX_TYPE_UINT32,count,nullptr,sharing_mode);}
|
|
|
|
|
|
|
|
|
|
#define CREATE_BUFFER_OBJECT(LargeName,type) Buffer *Create##LargeName(VkDeviceSize size,void *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size,data,sharing_mode);} \
|
|
|
|
|
Buffer *Create##LargeName(VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size,nullptr,sharing_mode);}
|
2019-04-11 23:02:38 +08:00
|
|
|
|
|
|
|
|
|
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
|
2019-04-19 21:14:56 +08:00
|
|
|
|
CREATE_BUFFER_OBJECT(SSBO,STORAGE)
|
2019-04-11 23:02:38 +08:00
|
|
|
|
CREATE_BUFFER_OBJECT(INBO,INDIRECT)
|
|
|
|
|
|
|
|
|
|
#undef CREATE_BUFFER_OBJECT
|
2019-04-11 22:40:13 +08:00
|
|
|
|
|
2019-05-07 12:46:25 +08:00
|
|
|
|
public: //material相关
|
2019-05-05 14:22:58 +08:00
|
|
|
|
|
2019-06-25 21:38:38 +08:00
|
|
|
|
Texture2D *CreateTexture2D(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout);
|
|
|
|
|
|
|
|
|
|
Texture2D *CreateTexture2DColor(const VkFormat video_format,uint32_t width,uint32_t height)
|
|
|
|
|
{
|
|
|
|
|
return CreateTexture2D(video_format,width,height,
|
|
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Texture2D *CreateTexture2DDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
|
|
|
|
{
|
|
|
|
|
return CreateTexture2D(video_format,width,height,
|
|
|
|
|
VK_IMAGE_ASPECT_DEPTH_BIT,
|
|
|
|
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 02:42:11 +08:00
|
|
|
|
Texture2D *CreateAttachmentTexture(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout)
|
2019-06-26 11:36:50 +08:00
|
|
|
|
{
|
2019-06-25 22:26:09 +08:00
|
|
|
|
return CreateTexture2D(video_format,width,height,aspectMask,usage|VK_IMAGE_USAGE_SAMPLED_BIT,image_layout);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 21:38:38 +08:00
|
|
|
|
Texture2D *CreateAttachmentTextureColor(const VkFormat video_format,uint32_t width,uint32_t height)
|
|
|
|
|
{
|
2019-06-25 22:26:09 +08:00
|
|
|
|
return CreateAttachmentTexture( video_format,width,height,
|
|
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
|
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
|
|
|
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
2019-06-25 21:38:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Texture2D *CreateAttachmentTextureDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
|
|
|
|
{
|
2019-06-25 22:26:09 +08:00
|
|
|
|
return CreateAttachmentTexture( video_format,width,height,
|
2019-07-10 21:48:07 +08:00
|
|
|
|
VK_IMAGE_ASPECT_DEPTH_BIT,//|VK_IMAGE_ASPECT_STENCIL_BIT,
|
2019-07-11 02:42:11 +08:00
|
|
|
|
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT,
|
2019-06-26 11:36:50 +08:00
|
|
|
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
|
|
|
|
}
|
2019-06-25 22:26:09 +08:00
|
|
|
|
|
2019-06-26 18:38:35 +08:00
|
|
|
|
Texture2D *CreateTexture2D( const VkFormat video_format,Buffer *buf,uint32_t width,uint32_t height,
|
|
|
|
|
const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
|
const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
|
const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
|
|
2019-06-25 22:26:09 +08:00
|
|
|
|
Texture2D *CreateTexture2D( const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,
|
|
|
|
|
const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
|
const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
|
|
|
|
const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
2019-06-26 11:36:50 +08:00
|
|
|
|
|
2019-06-26 18:38:35 +08:00
|
|
|
|
bool ChangeTexture2D(Texture2D *,Buffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height);
|
2019-05-21 00:45:37 +08:00
|
|
|
|
bool ChangeTexture2D(Texture2D *,void *data,uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size);
|
2019-05-18 16:10:42 +08:00
|
|
|
|
Sampler *CreateSampler(VkSamplerCreateInfo *);
|
2019-05-18 15:41:49 +08:00
|
|
|
|
|
2019-04-28 16:06:53 +08:00
|
|
|
|
ShaderModuleManage *CreateShaderModuleManage();
|
2019-04-27 21:23:57 +08:00
|
|
|
|
|
2019-05-07 12:46:25 +08:00
|
|
|
|
public: //Command Buffer 相关
|
2019-04-25 10:09:56 +08:00
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
CommandBuffer * CreateCommandBuffer(const VkExtent2D &extent,const uint32_t atta_count);
|
2019-07-02 21:09:20 +08:00
|
|
|
|
|
|
|
|
|
bool CreateAttachment( List<VkAttachmentReference> &ref_list,
|
|
|
|
|
List<VkAttachmentDescription> &desc_list,
|
|
|
|
|
const List<VkFormat> &color_format,
|
|
|
|
|
const VkFormat depth_format,
|
|
|
|
|
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
2019-07-03 19:45:39 +08:00
|
|
|
|
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
|
|
|
|
|
|
|
|
|
|
bool CreateColorAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const List<VkFormat> &color_format,const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)const;
|
|
|
|
|
bool CreateDepthAttachment( List<VkAttachmentReference> &ref_list,List<VkAttachmentDescription> &desc_list,const VkFormat &depth_format,const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
|
2019-07-02 21:09:20 +08:00
|
|
|
|
|
2019-07-03 19:45:39 +08:00
|
|
|
|
void CreateSubpassDependency(List<VkSubpassDependency> &dependency,const uint32_t count)const;
|
|
|
|
|
void CreateSubpassDescription(VkSubpassDescription &,const List<VkAttachmentReference> &)const;
|
2019-07-02 21:09:20 +08:00
|
|
|
|
|
|
|
|
|
RenderPass * CreateRenderPass( const List<VkAttachmentDescription> &desc_list,
|
|
|
|
|
const List<VkSubpassDescription> &subpass,
|
|
|
|
|
const List<VkSubpassDependency> &dependency,
|
|
|
|
|
const List<VkFormat> &color_format,
|
|
|
|
|
const VkFormat depth_format,
|
|
|
|
|
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
2019-07-03 19:45:39 +08:00
|
|
|
|
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
|
2019-07-02 21:09:20 +08:00
|
|
|
|
|
|
|
|
|
RenderPass * CreateRenderPass( const VkFormat color_format,
|
|
|
|
|
const VkFormat depth_format,
|
|
|
|
|
const VkImageLayout color_final_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
2019-07-03 19:45:39 +08:00
|
|
|
|
const VkImageLayout depth_final_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)const;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-07-16 20:57:17 +08:00
|
|
|
|
Fence * CreateFence(bool);
|
|
|
|
|
vulkan::Semaphore * CreateSem();
|
2019-07-13 18:23:43 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
|
|
|
|
RenderTarget *CreateRenderTarget(Framebuffer *);
|
2019-04-18 16:06:44 +08:00
|
|
|
|
};//class Device
|
2019-08-23 11:18:09 +08:00
|
|
|
|
|
|
|
|
|
Device *CreateRenderDevice(Instance *inst,Window *win,const PhysicalDevice *physical_device=nullptr);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_RENDER_SURFACE_INCLUDE
|