2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2019-04-16 02:21:35 +08:00
|
|
|
|
#include<hgl/type/Pair.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKSemaphore.h>
|
|
|
|
|
#include<hgl/graph/VKTexture.h>
|
|
|
|
|
#include<hgl/graph/VKImageView.h>
|
|
|
|
|
#include<hgl/graph/VKPipeline.h>
|
|
|
|
|
#include<hgl/graph/VKCommandBuffer.h>
|
|
|
|
|
//#include<hgl/graph/VKDescriptorSet.h>
|
|
|
|
|
#include<hgl/graph/VKRenderPass.h>
|
|
|
|
|
#include<hgl/graph/VKFramebuffer.h>
|
|
|
|
|
#include<hgl/graph/VKDescriptorSets.h>
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUDevice::GPUDevice(GPUDeviceAttribute *da)
|
2019-04-19 20:10:59 +08:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUDevice::~GPUDevice()
|
2019-04-18 22:24:39 +08:00
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
bool GPUDevice::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
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
texture_cmd_buf=CreateTextureCommandBuffer();
|
2020-10-21 12:39:22 +08:00
|
|
|
|
textureSQ=new GPUQueue(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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
VkCommandBuffer GPUDevice::CreateCommandBuffer()
|
2019-04-10 21:54:39 +08:00
|
|
|
|
{
|
2019-04-18 22:24:39 +08:00
|
|
|
|
if(!attr->cmd_pool)
|
2020-10-28 12:30:44 +08:00
|
|
|
|
return(VK_NULL_HANDLE);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
|
CommandBufferAllocateInfo cmd;
|
|
|
|
|
|
2019-06-20 21:41:40 +08:00
|
|
|
|
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)
|
2020-10-28 12:30:44 +08:00
|
|
|
|
return(VK_NULL_HANDLE);
|
|
|
|
|
|
|
|
|
|
return cmd_buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderCommand *GPUDevice::CreateRenderCommandBuffer()
|
|
|
|
|
{
|
|
|
|
|
VkCommandBuffer cb=CreateCommandBuffer();
|
|
|
|
|
|
|
|
|
|
if(cb==VK_NULL_HANDLE)return(nullptr);
|
|
|
|
|
|
|
|
|
|
return(new RenderCommand(attr->device,attr->cmd_pool,cb));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextureCommand *GPUDevice::CreateTextureCommandBuffer()
|
|
|
|
|
{
|
|
|
|
|
VkCommandBuffer cb=CreateCommandBuffer();
|
|
|
|
|
|
|
|
|
|
if(cb==VK_NULL_HANDLE)return(nullptr);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
return(new TextureCommand(attr->device,attr->cmd_pool,cb));
|
2019-04-10 21:54:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 11:26:38 +08:00
|
|
|
|
/**
|
|
|
|
|
* 创建栅栏
|
|
|
|
|
* @param create_signaled 是否创建初始信号
|
|
|
|
|
*/
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUFence *GPUDevice::CreateFence(bool create_signaled)
|
2019-04-19 19:58:01 +08:00
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
FenceCreateInfo fenceInfo(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);
|
|
|
|
|
|
2020-10-21 12:09:15 +08:00
|
|
|
|
return(new GPUFence(attr->device,fence));
|
2019-04-19 19:58:01 +08:00
|
|
|
|
}
|
2019-04-19 20:04:08 +08:00
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
GPUSemaphore *GPUDevice::CreateSemaphore()
|
2019-04-19 20:04:08 +08:00
|
|
|
|
{
|
2020-09-27 20:58:25 +08:00
|
|
|
|
SemaphoreCreateInfo SemaphoreCreateInfo;
|
2019-04-19 20:04:08 +08:00
|
|
|
|
|
|
|
|
|
VkSemaphore sem;
|
2020-09-27 20:58:25 +08:00
|
|
|
|
|
2019-04-19 20:04:08 +08:00
|
|
|
|
if(vkCreateSemaphore(attr->device, &SemaphoreCreateInfo, nullptr, &sem)!=VK_SUCCESS)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
return(new GPUSemaphore(attr->device,sem));
|
2019-04-19 20:04:08 +08:00
|
|
|
|
}
|
2019-04-10 21:54:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|