2023-05-10 02:32:03 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2021-06-16 11:43:19 +08:00
|
|
|
|
#include<hgl/graph/VKMaterial.h>
|
2023-03-20 13:55:47 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialDescriptorManager.h>
|
2021-09-14 20:31:15 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialParameters.h>
|
2023-02-13 11:50:55 +08:00
|
|
|
|
#include<hgl/graph/VKDescriptorSet.h>
|
2021-09-14 20:31:15 +08:00
|
|
|
|
#include<hgl/graph/VKShaderModuleMap.h>
|
2022-10-11 19:16:06 +08:00
|
|
|
|
#include<hgl/graph/VKVertexInputLayout.h>
|
2021-09-14 20:31:15 +08:00
|
|
|
|
#include"VKPipelineLayoutData.h"
|
2021-06-16 11:43:19 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-03-18 17:58:57 +08:00
|
|
|
|
DescriptorSet *GPUDevice::CreateDS(const PipelineLayoutData *pld,const DescriptorSetType &type)const
|
2021-09-14 20:31:15 +08:00
|
|
|
|
{
|
2023-02-13 11:48:53 +08:00
|
|
|
|
RANGE_CHECK_RETURN_NULLPTR(type);
|
2021-09-14 20:31:15 +08:00
|
|
|
|
|
|
|
|
|
const uint32_t binding_count=pld->binding_count[size_t(type)];
|
|
|
|
|
|
|
|
|
|
if(!binding_count)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
DescriptorSetAllocateInfo alloc_info;
|
|
|
|
|
|
|
|
|
|
alloc_info.descriptorPool = attr->desc_pool;
|
|
|
|
|
alloc_info.descriptorSetCount = 1;
|
|
|
|
|
alloc_info.pSetLayouts = pld->layouts+size_t(type);
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet desc_set;
|
|
|
|
|
|
|
|
|
|
if(vkAllocateDescriptorSets(attr->device,&alloc_info,&desc_set)!=VK_SUCCESS)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2023-02-13 11:48:53 +08:00
|
|
|
|
return(new DescriptorSet(attr->device,binding_count,pld->pipeline_layout,desc_set));
|
2021-09-14 20:31:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 21:46:16 +08:00
|
|
|
|
MaterialParameters *GPUDevice::CreateMP(const MaterialDescriptorManager *desc_manager,const PipelineLayoutData *pld,const DescriptorSetType &desc_set_type)
|
2021-09-14 20:31:15 +08:00
|
|
|
|
{
|
2023-03-21 21:46:16 +08:00
|
|
|
|
if(!desc_manager||!pld)return(nullptr);
|
2023-06-02 14:22:07 +08:00
|
|
|
|
RANGE_CHECK_RETURN_NULLPTR(desc_set_type)
|
2021-09-14 20:31:15 +08:00
|
|
|
|
|
2023-03-18 17:58:57 +08:00
|
|
|
|
DescriptorSet *ds=CreateDS(pld,desc_set_type);
|
2021-09-14 20:31:15 +08:00
|
|
|
|
|
|
|
|
|
if(!ds)return(nullptr);
|
|
|
|
|
|
2021-09-27 20:56:50 +08:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
const UTF8String addr_string=HexToString<char,uint64_t>((uint64_t)(ds->GetDescriptorSet()));
|
|
|
|
|
|
2023-03-21 21:46:16 +08:00
|
|
|
|
LOG_INFO(U8_TEXT("Create [DescriptSets:")+addr_string+("] OK! Material Name: \"")+desc_manager->GetMaterialName()+U8_TEXT("\" Type: ")+GetDescriptorSetTypeName(desc_set_type));
|
2021-09-27 20:56:50 +08:00
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
|
2023-03-21 21:46:16 +08:00
|
|
|
|
return(new MaterialParameters(desc_manager,desc_set_type,ds));
|
2021-09-14 20:31:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 21:53:51 +08:00
|
|
|
|
MaterialParameters *GPUDevice::CreateMP(Material *mtl,const DescriptorSetType &desc_set_type)
|
2021-09-14 20:31:15 +08:00
|
|
|
|
{
|
|
|
|
|
if(!mtl)return(nullptr);
|
|
|
|
|
|
|
|
|
|
return CreateMP(mtl->GetDescriptorSets(),mtl->GetPipelineLayoutData(),desc_set_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreateShaderStageList(List<VkPipelineShaderStageCreateInfo> &shader_stage_list,ShaderModuleMap *shader_maps)
|
|
|
|
|
{
|
|
|
|
|
const ShaderModule *sm;
|
|
|
|
|
|
|
|
|
|
const int shader_count=shader_maps->GetCount();
|
|
|
|
|
shader_stage_list.SetCount(shader_count);
|
|
|
|
|
|
|
|
|
|
VkPipelineShaderStageCreateInfo *p=shader_stage_list.GetData();
|
|
|
|
|
|
|
|
|
|
auto **itp=shader_maps->GetDataList();
|
|
|
|
|
for(int i=0;i<shader_count;i++)
|
|
|
|
|
{
|
2023-04-20 21:49:48 +08:00
|
|
|
|
sm=(*itp)->value;
|
2022-03-11 17:58:53 +08:00
|
|
|
|
hgl_cpy(p,sm->GetCreateInfo(),1);
|
2021-09-14 20:31:15 +08:00
|
|
|
|
|
|
|
|
|
++p;
|
|
|
|
|
++itp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 21:46:16 +08:00
|
|
|
|
Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps,MaterialDescriptorManager *desc_manager,VertexInput *vi)
|
2021-06-16 11:43:19 +08:00
|
|
|
|
{
|
|
|
|
|
const int shader_count=shader_maps->GetCount();
|
|
|
|
|
|
2023-03-19 19:41:21 +08:00
|
|
|
|
if(shader_count<1)
|
2021-06-16 11:43:19 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2023-03-21 21:46:16 +08:00
|
|
|
|
PipelineLayoutData *pld=CreatePipelineLayoutData(desc_manager);
|
2021-09-13 20:39:25 +08:00
|
|
|
|
|
2021-09-14 20:31:15 +08:00
|
|
|
|
if(!pld)
|
2021-06-16 11:43:19 +08:00
|
|
|
|
{
|
|
|
|
|
delete shader_maps;
|
2023-03-21 21:46:16 +08:00
|
|
|
|
SAFE_CLEAR(desc_manager);
|
2021-06-16 11:43:19 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-14 20:31:15 +08:00
|
|
|
|
MaterialData *data=new MaterialData;
|
|
|
|
|
|
2021-11-26 10:00:20 +08:00
|
|
|
|
data->name =mtl_name;
|
|
|
|
|
data->shader_maps =shader_maps;
|
2023-03-22 15:58:59 +08:00
|
|
|
|
data->desc_manager =desc_manager;
|
2023-03-19 19:41:21 +08:00
|
|
|
|
data->vertex_input =vi;
|
2021-09-14 20:31:15 +08:00
|
|
|
|
|
|
|
|
|
CreateShaderStageList(data->shader_stage_list,shader_maps);
|
2021-11-26 10:00:20 +08:00
|
|
|
|
|
2021-09-14 20:31:15 +08:00
|
|
|
|
data->pipeline_layout_data=pld;
|
2023-02-22 21:50:18 +08:00
|
|
|
|
|
2023-03-21 21:46:16 +08:00
|
|
|
|
if(desc_manager)
|
2023-02-22 21:50:18 +08:00
|
|
|
|
{
|
2023-02-22 21:53:51 +08:00
|
|
|
|
ENUM_CLASS_FOR(DescriptorSetType,int,dst)
|
2023-02-22 21:50:18 +08:00
|
|
|
|
{
|
2023-03-21 21:46:16 +08:00
|
|
|
|
if(desc_manager->hasSet((DescriptorSetType)dst))
|
|
|
|
|
data->mp_array[dst]=CreateMP(desc_manager,pld,(DescriptorSetType)dst);
|
2023-02-22 21:50:18 +08:00
|
|
|
|
else
|
|
|
|
|
data->mp_array[dst]=nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
hgl_zero(data->mp_array);
|
2021-09-14 20:31:15 +08:00
|
|
|
|
|
|
|
|
|
return(new Material(data));
|
2021-06-16 11:43:19 +08:00
|
|
|
|
}
|
2021-09-14 20:31:15 +08:00
|
|
|
|
VK_NAMESPACE_END
|