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/VKRenderPass.h>
|
|
|
|
|
#include<hgl/graph/VKFramebuffer.h>
|
2023-02-13 11:50:55 +08:00
|
|
|
|
#include<hgl/graph/VKDescriptorSet.h>
|
2021-09-22 16:28:39 +08:00
|
|
|
|
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
2024-10-23 01:12:36 +08:00
|
|
|
|
#include<hgl/graph/module/GraphModule.h>
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2024-10-23 01:12:36 +08:00
|
|
|
|
|
|
|
|
|
GraphModuleManager *InitGraphModuleManager(GPUDevice *dev);
|
|
|
|
|
bool ClearGraphModuleManager(GPUDevice *dev);
|
|
|
|
|
|
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
|
|
|
|
|
2021-03-25 20:00:19 +08:00
|
|
|
|
texture_queue=nullptr;
|
2019-06-14 10:32:43 +08:00
|
|
|
|
texture_cmd_buf=nullptr;
|
2019-07-13 02:37:19 +08:00
|
|
|
|
|
2024-10-23 01:12:36 +08:00
|
|
|
|
graph_module_manager=InitGraphModuleManager(this);
|
|
|
|
|
|
2021-09-22 16:28:39 +08:00
|
|
|
|
InitRenderPassManage();
|
|
|
|
|
|
2023-08-17 11:08:21 +08:00
|
|
|
|
sc_rt=nullptr;
|
2019-07-13 02:37:19 +08:00
|
|
|
|
Resize(attr->surface_caps.currentExtent);
|
2021-09-23 19:08:07 +08:00
|
|
|
|
|
2023-10-13 01:48:07 +08:00
|
|
|
|
texture_cmd_buf=CreateTextureCommandBuffer(attr->physical_device->GetDeviceName()+AnsiString(":TexCmdBuffer"));
|
2021-12-15 19:56:44 +08:00
|
|
|
|
texture_queue=CreateQueue();
|
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
|
|
|
|
{
|
2021-11-30 19:33:01 +08:00
|
|
|
|
ClearRenderPassManage();
|
|
|
|
|
|
2023-08-17 11:08:21 +08:00
|
|
|
|
SAFE_CLEAR(sc_rt);
|
2019-07-16 10:26:24 +08:00
|
|
|
|
|
2021-03-25 20:00:19 +08:00
|
|
|
|
SAFE_CLEAR(texture_queue);
|
2019-07-16 21:21:20 +08:00
|
|
|
|
SAFE_CLEAR(texture_cmd_buf);
|
2019-04-20 16:12:22 +08:00
|
|
|
|
|
2019-04-18 22:24:39 +08:00
|
|
|
|
delete attr;
|
2024-10-23 01:12:36 +08:00
|
|
|
|
|
|
|
|
|
//按设计,上面那些rt/queue/cmdbuf都需要走graph_module_manager释放和申请
|
|
|
|
|
ClearGraphModuleManager(this);
|
2019-04-18 22:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
bool GPUDevice::Resize(const VkExtent2D &extent)
|
2019-05-07 12:46:25 +08:00
|
|
|
|
{
|
2024-10-23 01:12:36 +08:00
|
|
|
|
graph_module_manager->OnResize(extent);
|
|
|
|
|
|
2023-08-17 11:08:21 +08:00
|
|
|
|
SAFE_CLEAR(sc_rt);
|
2019-06-14 10:32:43 +08:00
|
|
|
|
|
2021-12-15 19:56:44 +08:00
|
|
|
|
attr->RefreshSurfaceCaps();
|
2019-07-16 21:21:20 +08:00
|
|
|
|
|
2023-08-17 11:08:21 +08:00
|
|
|
|
sc_rt=CreateSwapchainRenderTarget();
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
2023-08-17 11:08:21 +08:00
|
|
|
|
return(sc_rt);
|
2019-05-07 12:46:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 01:48:07 +08:00
|
|
|
|
VkCommandBuffer GPUDevice::CreateCommandBuffer(const AnsiString &name)
|
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);
|
|
|
|
|
|
2023-10-13 01:48:07 +08:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
if(attr->debug_utils)
|
2023-10-13 02:01:57 +08:00
|
|
|
|
attr->debug_utils->SetCommandBuffer(cmd_buf,name);
|
2023-10-13 01:48:07 +08:00
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
return cmd_buf;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 01:48:07 +08:00
|
|
|
|
RenderCmdBuffer *GPUDevice::CreateRenderCommandBuffer(const AnsiString &name)
|
2020-10-28 12:30:44 +08:00
|
|
|
|
{
|
2023-10-13 01:48:07 +08:00
|
|
|
|
VkCommandBuffer cb=CreateCommandBuffer(name);
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
|
|
|
|
if(cb==VK_NULL_HANDLE)return(nullptr);
|
|
|
|
|
|
2020-11-16 16:42:20 +08:00
|
|
|
|
return(new RenderCmdBuffer(attr,cb));
|
2020-10-28 12:30:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 01:48:07 +08:00
|
|
|
|
TextureCmdBuffer *GPUDevice::CreateTextureCommandBuffer(const AnsiString &name)
|
2020-10-28 12:30:44 +08:00
|
|
|
|
{
|
2023-10-13 01:48:07 +08:00
|
|
|
|
VkCommandBuffer cb=CreateCommandBuffer(name);
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
|
|
|
|
if(cb==VK_NULL_HANDLE)return(nullptr);
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
2020-11-16 16:42:20 +08:00
|
|
|
|
return(new TextureCmdBuffer(attr,cb));
|
2019-04-10 21:54:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 11:26:38 +08:00
|
|
|
|
/**
|
|
|
|
|
* 创建栅栏
|
|
|
|
|
* @param create_signaled 是否创建初始信号
|
|
|
|
|
*/
|
2022-10-14 19:27:29 +08:00
|
|
|
|
Fence *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);
|
|
|
|
|
|
2022-10-14 19:27:29 +08:00
|
|
|
|
return(new Fence(attr->device,fence));
|
2019-04-19 19:58:01 +08:00
|
|
|
|
}
|
2019-04-19 20:04:08 +08:00
|
|
|
|
|
2022-10-14 19:40:16 +08:00
|
|
|
|
Semaphore *GPUDevice::CreateGPUSemaphore()
|
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);
|
|
|
|
|
|
2022-10-14 19:40:16 +08:00
|
|
|
|
return(new Semaphore(attr->device,sem));
|
2019-04-19 20:04:08 +08:00
|
|
|
|
}
|
2021-12-15 19:56:44 +08:00
|
|
|
|
|
2023-03-02 20:19:25 +08:00
|
|
|
|
DeviceQueue *GPUDevice::CreateQueue(const uint32_t fence_count,const bool create_signaled)
|
2021-12-15 19:56:44 +08:00
|
|
|
|
{
|
|
|
|
|
if(fence_count<=0)return(nullptr);
|
|
|
|
|
|
2022-10-14 19:27:29 +08:00
|
|
|
|
Fence **fence_list=new Fence *[fence_count];
|
2021-12-15 19:56:44 +08:00
|
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<fence_count;i++)
|
|
|
|
|
fence_list[i]=CreateFence(create_signaled);
|
|
|
|
|
|
2023-03-02 20:19:25 +08:00
|
|
|
|
return(new DeviceQueue(attr->device,attr->graphics_queue,fence_list,fence_count));
|
2021-12-15 19:56:44 +08:00
|
|
|
|
}
|
2019-04-10 21:54:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|