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>
|
|
|
|
|
#include<hgl/graph/VKDescriptorSets.h>
|
2021-09-22 16:28:39 +08:00
|
|
|
|
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
2019-04-10 21:54:39 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2021-09-23 19:08:07 +08:00
|
|
|
|
void LogSurfaceFormat(const List<VkSurfaceFormatKHR> &surface_format_list)
|
|
|
|
|
{
|
|
|
|
|
const uint32_t format_count=surface_format_list.GetCount();
|
|
|
|
|
const VkSurfaceFormatKHR *sf=surface_format_list.GetData();
|
|
|
|
|
|
|
|
|
|
LOG_INFO(OS_TEXT("Current physics device support ")+OSString::valueOf(format_count)+OS_TEXT(" surface format"));
|
|
|
|
|
|
|
|
|
|
const VulkanFormat *vf;
|
|
|
|
|
const VulkanColorSpace *cs;
|
|
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<format_count;i++)
|
|
|
|
|
{
|
|
|
|
|
vf=GetVulkanFormat(sf->format);
|
|
|
|
|
cs=GetVulkanColorSpace(sf->colorSpace);
|
|
|
|
|
|
|
|
|
|
LOG_INFO(" "+AnsiString::valueOf(i)+": "+AnsiString(vf->name)+", "+AnsiString(cs->name));
|
|
|
|
|
|
|
|
|
|
++sf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2021-09-22 16:28:39 +08:00
|
|
|
|
InitRenderPassManage();
|
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
swapchainRT=nullptr;
|
2019-07-13 02:37:19 +08:00
|
|
|
|
Resize(attr->surface_caps.currentExtent);
|
2021-09-23 19:08:07 +08:00
|
|
|
|
|
2021-12-15 19:56:44 +08:00
|
|
|
|
texture_cmd_buf=CreateTextureCommandBuffer();
|
|
|
|
|
texture_queue=CreateQueue();
|
|
|
|
|
|
2021-09-23 19:08:07 +08:00
|
|
|
|
LogSurfaceFormat(attr->surface_formats_list);
|
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();
|
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
SAFE_CLEAR(swapchainRT);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
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
|
|
|
|
|
2021-12-15 19:59:28 +08:00
|
|
|
|
swapchainRT=CreateSwapchainRenderTarget();
|
2019-07-16 19:59:53 +08:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
RenderCmdBuffer *GPUDevice::CreateRenderCommandBuffer()
|
2020-10-28 12:30:44 +08:00
|
|
|
|
{
|
|
|
|
|
VkCommandBuffer cb=CreateCommandBuffer();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
TextureCmdBuffer *GPUDevice::CreateTextureCommandBuffer()
|
2020-10-28 12:30:44 +08:00
|
|
|
|
{
|
|
|
|
|
VkCommandBuffer cb=CreateCommandBuffer();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-09-14 20:31:15 +08:00
|
|
|
|
GPUSemaphore *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);
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
return(new GPUSemaphore(attr->device,sem));
|
2019-04-19 20:04:08 +08:00
|
|
|
|
}
|
2021-12-15 19:56:44 +08:00
|
|
|
|
|
|
|
|
|
GPUQueue *GPUDevice::CreateQueue(const uint32_t fence_count,const bool create_signaled)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
return(new GPUQueue(attr->device,attr->graphics_queue,fence_list,fence_count));
|
|
|
|
|
}
|
2019-04-10 21:54:39 +08:00
|
|
|
|
VK_NAMESPACE_END
|