upgraded to newly DescriptorSetType
This commit is contained in:
parent
95064488db
commit
b35ef27610
@ -75,19 +75,19 @@ enum class DescriptorSetsType
|
|||||||
//设计使其对应shader中的set
|
//设计使其对应shader中的set
|
||||||
|
|
||||||
Global=0, ///<全局参数(如太阳光等)
|
Global=0, ///<全局参数(如太阳光等)
|
||||||
Material, ///<材质中永远不变的参数
|
PerFrame, ///<帧参数(如摄像机等)
|
||||||
// Texture, ///<材质中的纹理参数
|
PerMaterial,///<材质参数(如纹理等)
|
||||||
Value, ///<材质中的变量参数
|
PerObject, ///<对象参数(如模型矩阵等)
|
||||||
Primitive, ///<渲染实例参数(如Local2World matrix)
|
|
||||||
|
|
||||||
ENUM_CLASS_RANGE(Global,Primitive)
|
Instance,
|
||||||
|
Skeleton,
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(Global,Skeleton)
|
||||||
};//
|
};//
|
||||||
|
|
||||||
const DescriptorSetsType CheckDescriptorSetsType(const char *str);
|
|
||||||
|
|
||||||
constexpr char *DescriptSetsTypeName[]=
|
constexpr char *DescriptSetsTypeName[]=
|
||||||
{
|
{
|
||||||
"Global","Material","Value","Renderable"
|
"Global","PerFrame","PerMaterial","PerObject","Instance","Skeleton"
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char *GetDescriptorSetsTypeName(const enum class DescriptorSetsType &type)
|
inline const char *GetDescriptorSetsTypeName(const enum class DescriptorSetsType &type)
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
using ShaderStageCreateInfoList=List<VkPipelineShaderStageCreateInfo>;
|
||||||
|
|
||||||
|
using MaterialParameterArray=MaterialParameters *[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
|
||||||
struct MaterialData
|
struct MaterialData
|
||||||
{
|
{
|
||||||
UTF8String name;
|
UTF8String name;
|
||||||
@ -21,10 +23,7 @@ struct MaterialData
|
|||||||
|
|
||||||
PipelineLayoutData *pipeline_layout_data;
|
PipelineLayoutData *pipeline_layout_data;
|
||||||
|
|
||||||
struct
|
MaterialParameterArray mp_array;
|
||||||
{
|
|
||||||
MaterialParameters *m,*g,*r;
|
|
||||||
}mp;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -66,11 +65,12 @@ public:
|
|||||||
|
|
||||||
MaterialParameters * GetMP (const DescriptorSetsType &type)
|
MaterialParameters * GetMP (const DescriptorSetsType &type)
|
||||||
{
|
{
|
||||||
if(type==DescriptorSetsType::Material )return data->mp.m;else
|
RANGE_CHECK_RETURN_NULLPTR(type)
|
||||||
if(type==DescriptorSetsType::Primitive )return data->mp.r;else
|
|
||||||
if(type==DescriptorSetsType::Global )return data->mp.g;else
|
return data->mp_array[size_t(type)];
|
||||||
return(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool hasSet (const DescriptorSetsType &type)const;
|
||||||
};//class Material
|
};//class Material
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||||
|
@ -26,6 +26,7 @@ class MaterialDescriptorSets
|
|||||||
uint sd_count;
|
uint sd_count;
|
||||||
|
|
||||||
ShaderDescriptorList descriptor_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
ShaderDescriptorList descriptor_list[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||||
|
ShaderDescriptorList descriptor_list_by_set_type[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
|
||||||
Map<AnsiString,ShaderDescriptor *> sd_by_name;
|
Map<AnsiString,ShaderDescriptor *> sd_by_name;
|
||||||
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||||
@ -34,7 +35,7 @@ class MaterialDescriptorSets
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
DescriptorSetLayoutCreateInfo sds[size_t(DescriptorSetsType::RANGE_SIZE)];
|
DescriptorSetLayoutCreateInfo dsl_ci[size_t(DescriptorSetsType::RANGE_SIZE)];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -50,7 +51,11 @@ public:
|
|||||||
const int GetSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
|
const int GetSampler (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,name);}
|
||||||
const int GetAttachment (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
|
const int GetAttachment (const AnsiString &name )const{return GetBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,name);}
|
||||||
|
|
||||||
const DescriptorSetLayoutCreateInfo *GetBinding(const DescriptorSetsType &type)const{return sds+size_t(type);}
|
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetsType &type)const{return dsl_ci+size_t(type);}
|
||||||
|
|
||||||
|
const ShaderDescriptorList &GetDescriptorList(const DescriptorSetsType &type)const{return descriptor_list_by_set_type[size_t(type)];}
|
||||||
|
|
||||||
|
const bool hasSet(const DescriptorSetsType &type)const{return !descriptor_list_by_set_type[size_t(type)].IsEmpty();}
|
||||||
};//class MaterialDescriptorSets
|
};//class MaterialDescriptorSets
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_SETS_INCLUDE
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||||
#define HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
#define HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class MaterialInstance
|
class MaterialInstance
|
||||||
@ -10,23 +10,23 @@ class MaterialInstance
|
|||||||
|
|
||||||
VIL *vil;
|
VIL *vil;
|
||||||
|
|
||||||
MaterialParameters *mp_value;
|
MaterialParameters *mp_per_mi; ///<材质实例独有参数,对应PerMaterial合集
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class GPUDevice;
|
friend class GPUDevice;
|
||||||
|
|
||||||
MaterialInstance(Material *,VIL *,MaterialParameters *);
|
MaterialInstance(Material *,VIL *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~MaterialInstance();
|
virtual ~MaterialInstance()=default;
|
||||||
|
|
||||||
Material *GetMaterial(){return material;}
|
Material *GetMaterial(){return material;}
|
||||||
|
|
||||||
const VIL *GetVIL()const{return vil;}
|
const VIL *GetVIL()const{return vil;}
|
||||||
MaterialParameters *GetMP(){return mp_value;}
|
MaterialParameters *GetMP(){return mp_per_mi;}
|
||||||
MaterialParameters *GetMP(const DescriptorSetsType &type);
|
MaterialParameters *GetMP(const DescriptorSetsType &type){return material->GetMP(type);}
|
||||||
|
|
||||||
bool BindUBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
bool BindUBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||||
bool BindSSBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
bool BindSSBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
||||||
@ -34,4 +34,4 @@ public:
|
|||||||
};//class MaterialInstance
|
};//class MaterialInstance
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
const DescriptorSetsType GetType (){return ds_type;}
|
const DescriptorSetsType GetType (){return ds_type;}
|
||||||
DescriptorSet * GetDescriptorSet (){return descriptor_sets;}
|
DescriptorSet * GetDescriptorSet (){return descriptor_sets;}
|
||||||
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_sets->GetDescriptorSet();}
|
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_sets->GetDescriptorSet();}
|
||||||
|
|
||||||
const uint32_t GetCount ()const{return descriptor_sets->GetCount();}
|
const uint32_t GetCount ()const{return descriptor_sets->GetCount();}
|
||||||
@ -31,10 +31,11 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
#define MP_TYPE_IS(name) const bool is##name()const{return ds_type==DescriptorSetsType::name;}
|
#define MP_TYPE_IS(name) const bool is##name()const{return ds_type==DescriptorSetsType::name;}
|
||||||
MP_TYPE_IS(Material)
|
MP_TYPE_IS(Skeleton)
|
||||||
// MP_TYPE_IS(Texture)
|
MP_TYPE_IS(Instance)
|
||||||
MP_TYPE_IS(Value)
|
MP_TYPE_IS(PerObject)
|
||||||
MP_TYPE_IS(Primitive)
|
MP_TYPE_IS(PerMaterial)
|
||||||
|
MP_TYPE_IS(PerFrame)
|
||||||
MP_TYPE_IS(Global)
|
MP_TYPE_IS(Global)
|
||||||
#undef MP_TYPE_IS
|
#undef MP_TYPE_IS
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ struct ShaderStage
|
|||||||
|
|
||||||
VertexAttribType type; ///<成份数量(如vec4中的4)
|
VertexAttribType type; ///<成份数量(如vec4中的4)
|
||||||
|
|
||||||
bool global; ///<是否全局数据
|
|
||||||
bool dynamic; ///<是否动态数据
|
bool dynamic; ///<是否动态数据
|
||||||
};//struct ShaderStage
|
};//struct ShaderStage
|
||||||
|
|
||||||
|
2
res
2
res
@ -1 +1 @@
|
|||||||
Subproject commit 2f9727410cbe53f9867c544d8b6bd9f8ecdb97bf
|
Subproject commit 008dbd5353e6afe7add287333cbda1b5c5fffdec
|
@ -151,7 +151,7 @@ namespace hgl
|
|||||||
//为所有的材质绑定
|
//为所有的材质绑定
|
||||||
for(Material *mtl:material_sets)
|
for(Material *mtl:material_sets)
|
||||||
{
|
{
|
||||||
MaterialParameters *mp=mtl->GetMP(DescriptorSetsType::Primitive);
|
MaterialParameters *mp=mtl->GetMP(DescriptorSetsType::PerObject);
|
||||||
|
|
||||||
if(mp)
|
if(mp)
|
||||||
{
|
{
|
||||||
@ -219,7 +219,7 @@ namespace hgl
|
|||||||
MaterialParameters *mp;
|
MaterialParameters *mp;
|
||||||
|
|
||||||
for(int i=(int)DescriptorSetsType::BEGIN_RANGE;
|
for(int i=(int)DescriptorSetsType::BEGIN_RANGE;
|
||||||
i<(int)DescriptorSetsType::Primitive;
|
i<(int)DescriptorSetsType::PerObject;
|
||||||
i++)
|
i++)
|
||||||
{
|
{
|
||||||
mp=ri->GetMP((DescriptorSetsType)i);
|
mp=ri->GetMP((DescriptorSetsType)i);
|
||||||
@ -242,13 +242,13 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
mp=ri->GetMP(DescriptorSetsType::Primitive);
|
mp=ri->GetMP(DescriptorSetsType::PerObject);
|
||||||
|
|
||||||
if(mp)
|
if(mp)
|
||||||
{
|
{
|
||||||
ds_list[ds_count]=mp->GetVkDescriptorSet();
|
ds_list[ds_count]=mp->GetVkDescriptorSet();
|
||||||
++ds_count;
|
++ds_count;
|
||||||
|
|
||||||
cmd_buf->BindDescriptorSets(ri->GetPipelineLayout(),first_set,ds_list,ds_count,&ubo_offset,1);
|
cmd_buf->BindDescriptorSets(ri->GetPipelineLayout(),first_set,ds_list,ds_count,&ubo_offset,1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -123,7 +123,7 @@ bool RenderCmdBuffer::BindDescriptorSets(Renderable *ri)
|
|||||||
ds[count]=mp->GetVkDescriptorSet();
|
ds[count]=mp->GetVkDescriptorSet();
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
if((DescriptorSetsType)i==DescriptorSetsType::Primitive)
|
if((DescriptorSetsType)i==DescriptorSetsType::PerObject)
|
||||||
{
|
{
|
||||||
dynamic_count=mp->GetCount();
|
dynamic_count=mp->GetCount();
|
||||||
|
|
||||||
|
@ -108,9 +108,19 @@ Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *
|
|||||||
CreateShaderStageList(data->shader_stage_list,shader_maps);
|
CreateShaderStageList(data->shader_stage_list,shader_maps);
|
||||||
|
|
||||||
data->pipeline_layout_data=pld;
|
data->pipeline_layout_data=pld;
|
||||||
data->mp.m=CreateMP(mds,pld,DescriptorSetsType::Material );
|
|
||||||
data->mp.r=CreateMP(mds,pld,DescriptorSetsType::Primitive );
|
if(mds)
|
||||||
data->mp.g=CreateMP(mds,pld,DescriptorSetsType::Global );
|
{
|
||||||
|
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));
|
return(new Material(data));
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
MaterialData::~MaterialData()
|
MaterialData::~MaterialData()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(mp.m);
|
for(int i=0;i<int(DescriptorSetsType::RANGE_SIZE);i++)
|
||||||
SAFE_CLEAR(mp.r);
|
if(mp_array[i])
|
||||||
SAFE_CLEAR(mp.g);
|
delete mp_array[i];
|
||||||
|
|
||||||
delete shader_maps;
|
delete shader_maps;
|
||||||
SAFE_CLEAR(mds);
|
SAFE_CLEAR(mds);
|
||||||
@ -23,4 +23,9 @@ const VkPipelineLayout Material::GetPipelineLayout()const
|
|||||||
{
|
{
|
||||||
return data->pipeline_layout_data->pipeline_layout;
|
return data->pipeline_layout_data->pipeline_layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool Material::hasSet(const DescriptorSetsType &dst)const
|
||||||
|
{
|
||||||
|
return data->mds->hasSet(dst);
|
||||||
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -23,8 +23,8 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
|||||||
{
|
{
|
||||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||||
{
|
{
|
||||||
sds[i].bindingCount=0;
|
dsl_ci[i].bindingCount=0;
|
||||||
sds[i].pBindings=nullptr;
|
dsl_ci[i].pBindings=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -39,7 +39,9 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
|||||||
sd_by_name.Add(sp->name,sp);
|
sd_by_name.Add(sp->name,sp);
|
||||||
binding_map[size_t(sp->desc_type)].Add(sp->name,sp->binding);
|
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;
|
++sp;
|
||||||
}
|
}
|
||||||
@ -49,10 +51,10 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
|||||||
|
|
||||||
{
|
{
|
||||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
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];
|
dsl_ci[i].pBindings=new VkDescriptorSetLayoutBinding[dsl_ci[i].bindingCount];
|
||||||
sds_ptr[i]=(VkDescriptorSetLayoutBinding *)sds[i].pBindings;
|
sds_ptr[i]=(VkDescriptorSetLayoutBinding *)dsl_ci[i].pBindings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +96,8 @@ MaterialDescriptorSets::MaterialDescriptorSets(const UTF8String &name,ShaderDesc
|
|||||||
MaterialDescriptorSets::~MaterialDescriptorSets()
|
MaterialDescriptorSets::~MaterialDescriptorSets()
|
||||||
{
|
{
|
||||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
||||||
if(sds[i].bindingCount)
|
if(dsl_ci[i].bindingCount)
|
||||||
delete[] sds[i].pBindings;
|
delete[] dsl_ci[i].pBindings;
|
||||||
|
|
||||||
delete[] sd_list; //"delete[] nullptr" isn't bug.
|
delete[] sd_list; //"delete[] nullptr" isn't bug.
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
|
||||||
#include<hgl/graph/VKMaterialParameters.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKShaderModule.h>
|
#include<hgl/graph/VKShaderModule.h>
|
||||||
|
|
||||||
@ -15,72 +14,54 @@ MaterialInstance *GPUDevice::CreateMI(Material *mtl,const VILConfig *vil_cfg)
|
|||||||
|
|
||||||
if(!vil)return(nullptr);
|
if(!vil)return(nullptr);
|
||||||
|
|
||||||
MaterialParameters *mp=CreateMP(mtl,DescriptorSetsType::Value);
|
return(new MaterialInstance(mtl,vil));
|
||||||
|
|
||||||
return(new MaterialInstance(mtl,vil,mp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialInstance::MaterialInstance(Material *mtl,VIL *v,MaterialParameters *p)
|
MaterialInstance::MaterialInstance(Material *mtl,VIL *v)
|
||||||
{
|
{
|
||||||
material=mtl;
|
material=mtl;
|
||||||
|
|
||||||
vil=v;
|
vil=v;
|
||||||
|
|
||||||
mp_value=p;
|
mp_per_mi=mtl->GetMP(DescriptorSetsType::PerMaterial);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialInstance::BindUBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
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);
|
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);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialInstance::BindSSBO(const DescriptorSetsType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
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);
|
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);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialInstance::BindSampler(const DescriptorSetsType &type,const AnsiString &name,Texture *tex,Sampler *sampler)
|
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);
|
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);
|
return(true);
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -12,7 +12,7 @@ PipelineLayoutData *GPUDevice::CreatePipelineLayoutData(const MaterialDescriptor
|
|||||||
{
|
{
|
||||||
ENUM_CLASS_FOR(DescriptorSetsType,int,i)
|
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)
|
if(!dslci||dslci->bindingCount<=0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -40,7 +40,7 @@ const ShaderModule *RenderResource::CreateShaderModule(const OSString &filename,
|
|||||||
return sm;
|
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;
|
ShaderDescriptor *sd=sd_list;
|
||||||
uint str_len;
|
uint str_len;
|
||||||
@ -55,14 +55,23 @@ void LoadShaderDescriptor(const uint8 *data,ShaderDescriptor *sd_list,const uint
|
|||||||
data+=str_len;
|
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->set =*data++;
|
||||||
sd->binding =*data++;
|
sd->binding =*data++;
|
||||||
sd->stage_flag =*(uint32 *)data;
|
sd->stage_flag =*(uint32 *)data;
|
||||||
data+=sizeof(uint32);
|
data+=sizeof(uint32);
|
||||||
|
|
||||||
sd->set_type=CheckDescriptorSetsType(sd->name);
|
if(sd->set_type==DescriptorSetsType::PerObject)
|
||||||
|
|
||||||
if(sd->set_type==DescriptorSetsType::Primitive)
|
|
||||||
{
|
{
|
||||||
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_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;
|
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;
|
const uint8 ver=*sp;
|
||||||
++sp;
|
++sp;
|
||||||
|
|
||||||
if(ver!=2)
|
if(ver<2||ver>3)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
const uint32_t shader_bits=*(uint32_t *)sp;
|
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);
|
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);
|
mds=new MaterialDescriptorSets(mtl_name,sd_list,count);
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,6 @@
|
|||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
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);
|
#define AccessByPointer(data,type) *(type *)data;data+=sizeof(type);
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -109,7 +109,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value);
|
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::PerMaterial);
|
||||||
|
|
||||||
if(!mp)
|
if(!mp)
|
||||||
return(false);
|
return(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user