ULRE/src/SceneGraph/Vulkan/VKPipelineLayoutData.cpp

80 lines
2.3 KiB
C++
Raw Normal View History

2021-09-14 20:31:15 +08:00
#include"VKPipelineLayoutData.h"
#include<hgl/graph/VKDescriptorSet.h>
2021-09-14 20:31:15 +08:00
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKMaterialDescriptorManager.h>
2021-09-14 20:31:15 +08:00
VK_NAMESPACE_BEGIN
2023-06-14 16:49:19 +08:00
PipelineLayoutData *GPUDevice::CreatePipelineLayoutData(const MaterialDescriptorManager *desc_manager)
2021-09-14 20:31:15 +08:00
{
PipelineLayoutData *pld=hgl_zero_new<PipelineLayoutData>();
2023-03-21 21:46:16 +08:00
if(desc_manager)
2021-09-14 20:31:15 +08:00
{
ENUM_CLASS_FOR(DescriptorSetType,int,i)
2022-06-20 21:39:04 +08:00
{
2023-03-21 21:46:16 +08:00
const DescriptorSetLayoutCreateInfo *dslci=desc_manager->GetDSLCI((DescriptorSetType)i);
2022-06-20 21:39:04 +08:00
if(!dslci||dslci->bindingCount<=0)
continue;
if(pld->layouts[i])
2023-06-14 16:49:19 +08:00
vkDestroyDescriptorSetLayout(attr->device,pld->layouts[i],nullptr);
2022-06-20 21:39:04 +08:00
2023-06-14 16:49:19 +08:00
if(vkCreateDescriptorSetLayout(attr->device,dslci,nullptr,pld->layouts+i)!=VK_SUCCESS)
2022-06-20 21:39:04 +08:00
{
delete pld;
return(nullptr);
}
2021-09-14 20:31:15 +08:00
pld->vab_count[i]=dslci->bindingCount;
2021-09-14 20:31:15 +08:00
2022-06-20 21:39:04 +08:00
pld->fin_dsl[pld->fin_dsl_count]=pld->layouts[i];
++pld->fin_dsl_count;
}
2021-09-14 20:31:15 +08:00
2022-06-20 21:39:04 +08:00
if(pld->fin_dsl_count<=0)
2021-09-14 20:31:15 +08:00
{
delete pld;
return(nullptr);
}
}
2022-06-20 21:39:04 +08:00
else
2021-09-14 20:31:15 +08:00
{
//没有任何DescriptorSet的情况也是存在的
2021-09-14 20:31:15 +08:00
}
//VkPushConstantRange push_constant_range;
//push_constant_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
//push_constant_range.size = MAX_PUSH_CONSTANT_BYTES;
//push_constant_range.offset = 0;
PipelineLayoutCreateInfo pPipelineLayoutCreateInfo;
pPipelineLayoutCreateInfo.setLayoutCount = pld->fin_dsl_count;
pPipelineLayoutCreateInfo.pSetLayouts = pld->fin_dsl;
pPipelineLayoutCreateInfo.pushConstantRangeCount = 0;//1;
pPipelineLayoutCreateInfo.pPushConstantRanges = nullptr;//&push_constant_range;
2023-06-14 16:49:19 +08:00
pld->device=attr->device;
2021-09-14 20:31:15 +08:00
2023-06-14 16:49:19 +08:00
if(vkCreatePipelineLayout(attr->device,&pPipelineLayoutCreateInfo,nullptr,&(pld->pipeline_layout))!=VK_SUCCESS)
2021-09-14 20:31:15 +08:00
{
delete pld;
return(nullptr);
}
return(pld);
}
PipelineLayoutData::~PipelineLayoutData()
{
vkDestroyPipelineLayout(device,pipeline_layout,nullptr);
ENUM_CLASS_FOR(DescriptorSetType,int,i)
2021-09-14 20:31:15 +08:00
if(layouts[i])
vkDestroyDescriptorSetLayout(device,layouts[i],nullptr);
}
VK_NAMESPACE_END