upgraded to newly DescriptorSetType
This commit is contained in:
@@ -123,7 +123,7 @@ bool RenderCmdBuffer::BindDescriptorSets(Renderable *ri)
|
||||
ds[count]=mp->GetVkDescriptorSet();
|
||||
++count;
|
||||
|
||||
if((DescriptorSetsType)i==DescriptorSetsType::Primitive)
|
||||
if((DescriptorSetsType)i==DescriptorSetsType::PerObject)
|
||||
{
|
||||
dynamic_count=mp->GetCount();
|
||||
|
||||
|
@@ -108,9 +108,19 @@ Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *
|
||||
CreateShaderStageList(data->shader_stage_list,shader_maps);
|
||||
|
||||
data->pipeline_layout_data=pld;
|
||||
data->mp.m=CreateMP(mds,pld,DescriptorSetsType::Material );
|
||||
data->mp.r=CreateMP(mds,pld,DescriptorSetsType::Primitive );
|
||||
data->mp.g=CreateMP(mds,pld,DescriptorSetsType::Global );
|
||||
|
||||
if(mds)
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetsType,int,dst)
|
||||
{
|
||||
if(mds->hasSet((DescriptorSetsType)dst))
|
||||
data->mp_array[dst]=CreateMP(mds,pld,(DescriptorSetsType)dst);
|
||||
else
|
||||
data->mp_array[dst]=nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
hgl_zero(data->mp_array);
|
||||
|
||||
return(new Material(data));
|
||||
}
|
||||
|
@@ -5,9 +5,9 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
MaterialData::~MaterialData()
|
||||
{
|
||||
SAFE_CLEAR(mp.m);
|
||||
SAFE_CLEAR(mp.r);
|
||||
SAFE_CLEAR(mp.g);
|
||||
for(int i=0;i<int(DescriptorSetsType::RANGE_SIZE);i++)
|
||||
if(mp_array[i])
|
||||
delete mp_array[i];
|
||||
|
||||
delete shader_maps;
|
||||
SAFE_CLEAR(mds);
|
||||
@@ -23,4 +23,9 @@ const VkPipelineLayout Material::GetPipelineLayout()const
|
||||
{
|
||||
return data->pipeline_layout_data->pipeline_layout;
|
||||
}
|
||||
|
||||
const bool Material::hasSet(const DescriptorSetsType &dst)const
|
||||
{
|
||||
return data->mds->hasSet(dst);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -23,8 +23,8 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||
{
|
||||
sds[i].bindingCount=0;
|
||||
sds[i].pBindings=nullptr;
|
||||
dsl_ci[i].bindingCount=0;
|
||||
dsl_ci[i].pBindings=nullptr;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -39,7 +39,9 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
||||
sd_by_name.Add(sp->name,sp);
|
||||
binding_map[size_t(sp->desc_type)].Add(sp->name,sp->binding);
|
||||
|
||||
++sds[size_t(sp->set_type)].bindingCount;
|
||||
++dsl_ci[size_t(sp->set_type)].bindingCount;
|
||||
|
||||
descriptor_list_by_set_type[size_t(sp->set_type)].Add(sp);
|
||||
|
||||
++sp;
|
||||
}
|
||||
@@ -49,10 +51,10 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
||||
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||
if(sds[i].bindingCount>0)
|
||||
if(dsl_ci[i].bindingCount>0)
|
||||
{
|
||||
sds[i].pBindings=new VkDescriptorSetLayoutBinding[sds[i].bindingCount];
|
||||
sds_ptr[i]=(VkDescriptorSetLayoutBinding *)sds[i].pBindings;
|
||||
dsl_ci[i].pBindings=new VkDescriptorSetLayoutBinding[dsl_ci[i].bindingCount];
|
||||
sds_ptr[i]=(VkDescriptorSetLayoutBinding *)dsl_ci[i].pBindings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +96,8 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
||||
MaterialDescriptorSets::~MaterialDescriptorSets()
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||
if(sds[i].bindingCount)
|
||||
delete[] sds[i].pBindings;
|
||||
if(dsl_ci[i].bindingCount)
|
||||
delete[] dsl_ci[i].pBindings;
|
||||
|
||||
delete[] sd_list; //"delete[] nullptr" isn't bug.
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
|
||||
@@ -15,72 +14,54 @@ MaterialInstance *GPUDevice::CreateMI(Material *mtl,const VILConfig *vil_cfg)
|
||||
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
MaterialParameters *mp=CreateMP(mtl,DescriptorSetsType::Value);
|
||||
|
||||
return(new MaterialInstance(mtl,vil,mp));
|
||||
return(new MaterialInstance(mtl,vil));
|
||||
}
|
||||
|
||||
MaterialInstance::MaterialInstance(Material *mtl,VIL *v,MaterialParameters *p)
|
||||
MaterialInstance::MaterialInstance(Material *mtl,VIL *v)
|
||||
{
|
||||
material=mtl;
|
||||
|
||||
vil=v;
|
||||
|
||||
mp_value=p;
|
||||
}
|
||||
|
||||
MaterialInstance::~MaterialInstance()
|
||||
{
|
||||
SAFE_CLEAR(mp_value);
|
||||
}
|
||||
|
||||
MaterialParameters *MaterialInstance::GetMP(const DescriptorSetsType &type)
|
||||
{
|
||||
//if(type==DescriptorSetsType::Texture
|
||||
// return mp_texture;
|
||||
|
||||
if(type==DescriptorSetsType::Value)
|
||||
return mp_value;
|
||||
|
||||
return material->GetMP(type);
|
||||
mp_per_mi=mtl->GetMP(DescriptorSetsType::PerMaterial);
|
||||
}
|
||||
|
||||
bool MaterialInstance::BindUBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
||||
{
|
||||
MaterialParameters *mp_global=GetMP(type);
|
||||
MaterialParameters *mp=GetMP(type);
|
||||
|
||||
if(!mp_global)
|
||||
if(!mp)
|
||||
return(false);
|
||||
|
||||
if(!mp_global->BindUBO(name,ubo,dynamic))return(false);
|
||||
if(!mp->BindUBO(name,ubo,dynamic))return(false);
|
||||
|
||||
mp_global->Update();
|
||||
mp->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool MaterialInstance::BindSSBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
||||
{
|
||||
MaterialParameters *mp_global=GetMP(type);
|
||||
MaterialParameters *mp=GetMP(type);
|
||||
|
||||
if(!mp_global)
|
||||
if(!mp)
|
||||
return(false);
|
||||
|
||||
if(!mp_global->BindSSBO(name,ubo,dynamic))return(false);
|
||||
if(!mp->BindSSBO(name,ubo,dynamic))return(false);
|
||||
|
||||
mp_global->Update();
|
||||
mp->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool MaterialInstance::BindSampler(const DescriptorSetsType &type,const AnsiString &name,Texture *tex,Sampler *sampler)
|
||||
{
|
||||
MaterialParameters *mp_global=GetMP(type);
|
||||
MaterialParameters *mp=GetMP(type);
|
||||
|
||||
if(!mp_global)
|
||||
if(!mp)
|
||||
return(false);
|
||||
|
||||
if(!mp_global->BindSampler(name,tex,sampler))return(false);
|
||||
if(!mp->BindSampler(name,tex,sampler))return(false);
|
||||
|
||||
mp_global->Update();
|
||||
mp->Update();
|
||||
return(true);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -12,7 +12,7 @@ PipelineLayoutData *GPUDevice::CreatePipelineLayoutData(const MaterialDescriptor
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||
{
|
||||
const DescriptorSetLayoutCreateInfo *dslci=mds->GetBinding((DescriptorSetsType)i);
|
||||
const DescriptorSetLayoutCreateInfo *dslci=mds->GetDSLCI((DescriptorSetsType)i);
|
||||
|
||||
if(!dslci||dslci->bindingCount<=0)
|
||||
continue;
|
||||
|
@@ -40,7 +40,7 @@ const ShaderModule *RenderResource::CreateShaderModule(const OSString &filename,
|
||||
return sm;
|
||||
}
|
||||
|
||||
void LoadShaderDescriptor(const uint8 *data,ShaderDescriptor *sd_list,const uint count)
|
||||
void LoadShaderDescriptor(const uint8 *data,ShaderDescriptor *sd_list,const uint count,const uint8 ver)
|
||||
{
|
||||
ShaderDescriptor *sd=sd_list;
|
||||
uint str_len;
|
||||
@@ -55,14 +55,23 @@ void LoadShaderDescriptor(const uint8 *data,ShaderDescriptor *sd_list,const uint
|
||||
data+=str_len;
|
||||
}
|
||||
|
||||
if(ver==3)
|
||||
sd->set_type =(DescriptorSetsType)*data++;
|
||||
else
|
||||
if(ver==2) //以下是旧的,未来不用了,现仅保证能运行
|
||||
{
|
||||
if(sd->name[0]=='g')sd->set_type=DescriptorSetsType::Global;else
|
||||
if(sd->name[0]=='m')sd->set_type=DescriptorSetsType::PerMaterial;else
|
||||
if(sd->name[0]=='r')sd->set_type=DescriptorSetsType::PerObject;else
|
||||
sd->set_type=DescriptorSetsType::PerFrame;
|
||||
}
|
||||
|
||||
sd->set =*data++;
|
||||
sd->binding =*data++;
|
||||
sd->stage_flag =*(uint32 *)data;
|
||||
data+=sizeof(uint32);
|
||||
|
||||
sd->set_type=CheckDescriptorSetsType(sd->name);
|
||||
|
||||
if(sd->set_type==DescriptorSetsType::Primitive)
|
||||
if(sd->set_type==DescriptorSetsType::PerObject)
|
||||
{
|
||||
if(sd->desc_type==VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)sd->desc_type=VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;else
|
||||
if(sd->desc_type==VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)sd->desc_type=VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
|
||||
@@ -107,7 +116,7 @@ Material *RenderResource::CreateMaterial(const OSString &filename)
|
||||
const uint8 ver=*sp;
|
||||
++sp;
|
||||
|
||||
if(ver!=2)
|
||||
if(ver<2||ver>3)
|
||||
return(nullptr);
|
||||
|
||||
const uint32_t shader_bits=*(uint32_t *)sp;
|
||||
@@ -160,7 +169,7 @@ Material *RenderResource::CreateMaterial(const OSString &filename)
|
||||
{
|
||||
ShaderDescriptor *sd_list=hgl_zero_new<ShaderDescriptor>(count);
|
||||
|
||||
LoadShaderDescriptor(sp,sd_list,count);
|
||||
LoadShaderDescriptor(sp,sd_list,count,ver);
|
||||
|
||||
mds=new MaterialDescriptorSets(mtl_name,sd_list,count);
|
||||
}
|
||||
|
@@ -5,18 +5,6 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
const DescriptorSetsType CheckDescriptorSetsType(const char *str)
|
||||
{
|
||||
if(str[1]=='_')
|
||||
{
|
||||
if(str[0]=='m')return DescriptorSetsType::Material;
|
||||
if(str[0]=='g')return DescriptorSetsType::Global;
|
||||
if(str[0]=='r')return DescriptorSetsType::Primitive;
|
||||
}
|
||||
|
||||
return DescriptorSetsType::Value;
|
||||
}
|
||||
|
||||
#define AccessByPointer(data,type) *(type *)data;data+=sizeof(type);
|
||||
|
||||
namespace
|
||||
|
Reference in New Issue
Block a user