2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKDevice.h>
|
2019-04-16 02:21:35 +08:00
|
|
|
|
#include<hgl/type/Pair.h>
|
2019-07-16 20:57:17 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKSemaphore.h>
|
2019-06-26 16:03:21 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKTexture.h>
|
2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKImageView.h>
|
2020-09-19 23:49:32 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKPipeline.h>
|
2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
|
|
|
|
//#include<hgl/graph/vulkan/VKDescriptorSet.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKRenderPass.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-19 20:10:59 +08:00
|
|
|
|
Device::Device(DeviceAttribute *da)
|
|
|
|
|
{
|
|
|
|
|
attr=da;
|
2019-05-05 14:22:58 +08:00
|
|
|
|
|
2019-07-16 21:21:20 +08:00
|
|
|
|
textureSQ=nullptr;
|
2019-06-14 10:32:43 +08:00
|
|
|
|
texture_cmd_buf=nullptr;
|
2019-07-13 02:37:19 +08:00
|
|
|
|
|
2019-07-16 10:26:24 +08:00
|
|
|
|
swapchain=nullptr;
|
2019-07-16 19:59:53 +08:00
|
|
|
|
swapchainRT=nullptr;
|
2019-07-13 02:37:19 +08:00
|
|
|
|
Resize(attr->surface_caps.currentExtent);
|
2019-04-19 20:10:59 +08:00
|
|
|
|
}
|
2019-04-27 21:49:22 +08:00
|
|
|
|
|
2019-04-18 22:24:39 +08:00
|
|
|
|
Device::~Device()
|
|
|
|
|
{
|
2019-07-16 19:59:53 +08:00
|
|
|
|
SAFE_CLEAR(swapchainRT);
|
2019-07-16 10:26:24 +08:00
|
|
|
|
SAFE_CLEAR(swapchain);
|
|
|
|
|
|
2019-07-16 21:21:20 +08:00
|
|
|
|
SAFE_CLEAR(textureSQ);
|
|
|
|
|
SAFE_CLEAR(texture_cmd_buf);
|
2019-04-20 16:12:22 +08:00
|
|
|
|
|
2019-04-18 22:24:39 +08:00
|
|
|
|
delete attr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
bool Device::Resize(const VkExtent2D &extent)
|
2019-05-07 12:46:25 +08:00
|
|
|
|
{
|
2019-07-16 19:59:53 +08:00
|
|
|
|
SAFE_CLEAR(swapchainRT);
|
|
|
|
|
SAFE_CLEAR(swapchain);
|
2019-06-14 10:32:43 +08:00
|
|
|
|
|
2019-07-16 21:21:20 +08:00
|
|
|
|
SAFE_CLEAR(textureSQ);
|
|
|
|
|
SAFE_CLEAR(texture_cmd_buf);
|
|
|
|
|
|
2019-07-17 04:49:16 +08:00
|
|
|
|
attr->Refresh();
|
2019-11-26 00:33:24 +08:00
|
|
|
|
|
|
|
|
|
if(!CreateSwapchain(extent))
|
|
|
|
|
return(false);
|
2019-05-07 12:46:25 +08:00
|
|
|
|
|
2019-07-16 21:21:20 +08:00
|
|
|
|
texture_cmd_buf=CreateCommandBuffer(extent,0);
|
|
|
|
|
textureSQ=new SubmitQueue(this,attr->graphics_queue,1);
|
2019-05-07 12:46:25 +08:00
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
swapchainRT=new SwapchainRenderTarget(this,swapchain);
|
|
|
|
|
|
2019-05-07 12:46:25 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
CommandBuffer *Device::CreateCommandBuffer(const VkExtent2D &extent,const uint32_t atta_count)
|
2019-04-10 21:54:39 +08:00
|
|
|
|
{
|
2019-04-18 22:24:39 +08:00
|
|
|
|
if(!attr->cmd_pool)
|
2019-04-10 21:54:39 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2019-06-20 21:41:40 +08:00
|
|
|
|
VkCommandBufferAllocateInfo cmd;
|
|
|
|
|
cmd.sType =VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
|
|
|
|
cmd.pNext =nullptr;
|
|
|
|
|
cmd.commandPool =attr->cmd_pool;
|
|
|
|
|
cmd.level =VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
|
|
|
|
cmd.commandBufferCount =1;
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
VkCommandBuffer cmd_buf;
|
|
|
|
|
|
2019-04-18 22:24:39 +08:00
|
|
|
|
VkResult res=vkAllocateCommandBuffers(attr->device,&cmd,&cmd_buf);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
if(res!=VK_SUCCESS)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2019-07-13 02:37:19 +08:00
|
|
|
|
return(new CommandBuffer(attr->device,extent,atta_count,attr->cmd_pool,cmd_buf));
|
2019-04-10 21:54:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 11:26:38 +08:00
|
|
|
|
/**
|
|
|
|
|
* 创建栅栏
|
|
|
|
|
* @param create_signaled 是否创建初始信号
|
|
|
|
|
*/
|
|
|
|
|
Fence *Device::CreateFence(bool create_signaled)
|
2019-04-19 19:58:01 +08:00
|
|
|
|
{
|
|
|
|
|
VkFenceCreateInfo fenceInfo;
|
|
|
|
|
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
|
|
|
|
fenceInfo.pNext = nullptr;
|
2019-06-26 11:26:38 +08:00
|
|
|
|
fenceInfo.flags = create_signaled?VK_FENCE_CREATE_SIGNALED_BIT:0;
|
2019-04-19 19:58:01 +08:00
|
|
|
|
|
2019-04-20 16:12:22 +08:00
|
|
|
|
VkFence fence;
|
2019-04-19 19:58:01 +08:00
|
|
|
|
|
2019-04-20 16:12:22 +08:00
|
|
|
|
if(vkCreateFence(attr->device, &fenceInfo, nullptr, &fence)!=VK_SUCCESS)
|
2019-04-19 19:58:01 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2019-04-20 16:12:22 +08:00
|
|
|
|
return(new Fence(attr->device,fence));
|
2019-04-19 19:58:01 +08:00
|
|
|
|
}
|
2019-04-19 20:04:08 +08:00
|
|
|
|
|
2019-07-16 20:57:17 +08:00
|
|
|
|
vulkan::Semaphore *Device::CreateSem()
|
2019-04-19 20:04:08 +08:00
|
|
|
|
{
|
|
|
|
|
VkSemaphoreCreateInfo SemaphoreCreateInfo;
|
|
|
|
|
SemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
|
|
|
SemaphoreCreateInfo.pNext = nullptr;
|
|
|
|
|
SemaphoreCreateInfo.flags = 0;
|
|
|
|
|
|
|
|
|
|
VkSemaphore sem;
|
|
|
|
|
if(vkCreateSemaphore(attr->device, &SemaphoreCreateInfo, nullptr, &sem)!=VK_SUCCESS)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2019-07-16 20:57:17 +08:00
|
|
|
|
return(new vulkan::Semaphore(attr->device,sem));
|
2019-04-19 20:04:08 +08:00
|
|
|
|
}
|
2019-04-19 20:10:59 +08:00
|
|
|
|
|
2020-09-19 23:49:32 +08:00
|
|
|
|
RenderTarget *Device::CreateRenderTarget(Framebuffer *fb)
|
2019-04-28 16:06:53 +08:00
|
|
|
|
{
|
2020-09-19 23:49:32 +08:00
|
|
|
|
return(new RenderTarget(this,fb));
|
2019-04-28 16:06:53 +08:00
|
|
|
|
}
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2020-09-19 23:49:32 +08:00
|
|
|
|
Pipeline *CreatePipeline(VkDevice device,VkPipelineCache pipeline_cache,PipelineData *data,const Material *material,const RenderTarget *rt);
|
|
|
|
|
|
|
|
|
|
Pipeline *Device::CreatePipeline(PipelineData *pd,const Material *mtl,const RenderTarget *rt)
|
2019-07-16 19:59:53 +08:00
|
|
|
|
{
|
2020-09-19 23:49:32 +08:00
|
|
|
|
return VK_NAMESPACE::CreatePipeline(attr->device,attr->pipeline_cache,pd,mtl,rt);
|
2019-07-16 19:59:53 +08:00
|
|
|
|
}
|
2019-04-10 21:54:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|