finished write codes of CreateMaterial from MaterialCreateInfo
This commit is contained in:
2
CMCore
2
CMCore
Submodule CMCore updated: 2f4a583b9c...b6ee9c816f
Submodule CMSceneGraph updated: bcf0855460...404d0d8478
BIN
GLSLCompiler.dll
BIN
GLSLCompiler.dll
Binary file not shown.
@@ -2,15 +2,13 @@
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKShaderDescriptor.h>
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialDescriptorManager
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
||||
bool set_has_desc[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
Map<AnsiString,int> binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
private:
|
||||
@@ -22,6 +20,7 @@ private:
|
||||
public:
|
||||
|
||||
MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint);
|
||||
MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &);
|
||||
~MaterialDescriptorManager();
|
||||
|
||||
const UTF8String &GetMaterialName()const{return mtl_name;}
|
||||
@@ -35,9 +34,7 @@ public:
|
||||
|
||||
const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);}
|
||||
|
||||
//const ShaderDescriptorList &GetDescriptorList(const DescriptorSetType &type)const{return sd_list_by_set_type[size_t(type)];}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const{return set_has_desc[size_t(type)];}
|
||||
const bool hasSet(const DescriptorSetType &type)const{return dsl_ci[size_t(type)].bindingCount>0;}
|
||||
//!sd_list_by_set_type[size_t(type)].IsEmpty();}
|
||||
};//class MaterialDescriptorManager
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -57,5 +57,7 @@ public:
|
||||
bool AddSampler(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const SamplerType &st,const AnsiString &name);
|
||||
|
||||
bool CreateShader();
|
||||
|
||||
const MaterialDescriptorInfo &GetMDI()const{return mdm;}
|
||||
};//class MaterialCreateInfo
|
||||
SHADERGEN_NAMESPACE_END
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKShaderDescriptor.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
#include<hgl/shadergen/ShaderGenNamespace.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
@@ -15,22 +14,6 @@ SHADERGEN_NAMESPACE_BEGIN
|
||||
*/
|
||||
class MaterialDescriptorInfo
|
||||
{
|
||||
struct ShaderDescriptorSet
|
||||
{
|
||||
DescriptorSetType set_type;
|
||||
|
||||
int set;
|
||||
int count;
|
||||
|
||||
ObjectMap<AnsiString,ShaderDescriptor> descriptor_map;
|
||||
|
||||
public:
|
||||
|
||||
ShaderDescriptor *AddDescriptor(VkShaderStageFlagBits ssb,ShaderDescriptor *new_sd); ///<添加一个描述符,如果它本身存在,则返回false
|
||||
};
|
||||
|
||||
using ShaderDescriptorSetArray=ShaderDescriptorSet[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
ShaderDescriptorSetArray desc_set_array;
|
||||
|
||||
Map<AnsiString,AnsiString> struct_map;
|
||||
@@ -68,6 +51,11 @@ public:
|
||||
|
||||
void Resort(); //排序产生set号与binding号
|
||||
|
||||
const ShaderDescriptorSetArray &Get()const
|
||||
{
|
||||
return desc_set_array;
|
||||
}
|
||||
|
||||
const bool hasSet(const DescriptorSetType &type)const
|
||||
{
|
||||
return desc_set_array[size_t(type)].count>0;
|
||||
|
@@ -16,7 +16,5 @@ public:
|
||||
|
||||
int AddInput(const graph::VAT &type,const AnsiString &name);
|
||||
int AddInput(const AnsiString &type,const AnsiString &name);
|
||||
|
||||
const hgl::graph::ShaderAttributeArray &GetInput()const;
|
||||
};
|
||||
SHADERGEN_NAMESPACE_END
|
||||
|
@@ -18,13 +18,6 @@ MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,Shad
|
||||
|
||||
if(sd_count<=0)return;
|
||||
|
||||
ShaderDescriptorList sd_list_by_desc_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
hgl_zero(set_has_desc);
|
||||
|
||||
uint dslb_count=0;
|
||||
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetType,int,i)
|
||||
{
|
||||
dsl_ci[i].bindingCount=0;
|
||||
@@ -36,28 +29,20 @@ MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,Shad
|
||||
|
||||
for(uint i=0;i<sd_count;i++)
|
||||
{
|
||||
if(sp->desc_type>=VK_DESCRIPTOR_TYPE_BEGIN_RANGE
|
||||
&&sp->desc_type<=VK_DESCRIPTOR_TYPE_END_RANGE)
|
||||
sd_list_by_desc_type[(size_t)sp->desc_type].Add(sp);
|
||||
|
||||
binding_map[size_t(sp->desc_type)].Add(sp->name,sp->binding);
|
||||
|
||||
++dsl_ci[size_t(sp->set_type)].bindingCount;
|
||||
|
||||
++dslb_count;
|
||||
|
||||
set_has_desc[size_t(sp->set_type)]=true;
|
||||
|
||||
++sp;
|
||||
}
|
||||
}
|
||||
|
||||
all_dslb=new VkDescriptorSetLayoutBinding[dslb_count];
|
||||
all_dslb=new VkDescriptorSetLayoutBinding[sd_count];
|
||||
|
||||
{
|
||||
VkDescriptorSetLayoutBinding *dsl_bind[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
VkDescriptorSetLayoutBinding *dslp=all_dslb;
|
||||
|
||||
{
|
||||
ENUM_CLASS_FOR(DescriptorSetType,int,i)
|
||||
if(dsl_ci[i].bindingCount>0)
|
||||
{
|
||||
@@ -65,7 +50,6 @@ MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,Shad
|
||||
dsl_bind[i]=dslp;
|
||||
dslp+=dsl_ci[i].bindingCount;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ShaderDescriptor *sp=sd_list;
|
||||
@@ -82,6 +66,58 @@ MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,Shad
|
||||
}
|
||||
}
|
||||
|
||||
MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,const ShaderDescriptorSetArray &sds_array)
|
||||
{
|
||||
mtl_name=name;
|
||||
|
||||
uint sd_count=0;
|
||||
|
||||
ENUM_CLASS_FOR(DescriptorSetType,int,i)
|
||||
{
|
||||
dsl_ci[i].bindingCount=sds_array[i].count;
|
||||
dsl_ci[i].pBindings=nullptr;
|
||||
|
||||
sd_count+=sds_array[i].count;
|
||||
|
||||
}
|
||||
|
||||
if(sd_count<=0)return;
|
||||
|
||||
all_dslb=new VkDescriptorSetLayoutBinding[sd_count];
|
||||
|
||||
{
|
||||
VkDescriptorSetLayoutBinding *dsl_bind[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
VkDescriptorSetLayoutBinding *dslp=all_dslb;
|
||||
|
||||
ENUM_CLASS_FOR(DescriptorSetType,int,i)
|
||||
if(dsl_ci[i].bindingCount>0)
|
||||
{
|
||||
dsl_ci[i].pBindings=dslp;
|
||||
dsl_bind[i]=dslp;
|
||||
dslp+=dsl_ci[i].bindingCount;
|
||||
}
|
||||
|
||||
ENUM_CLASS_FOR(DescriptorSetType,int,i)
|
||||
{
|
||||
auto *sp=sds_array[i].descriptor_map.GetDataList();
|
||||
ShaderDescriptor *sd;
|
||||
|
||||
for(int j=0;j<sds_array[i].count;j++)
|
||||
{
|
||||
sd=(*sp)->right;
|
||||
|
||||
binding_map[size_t(sd->desc_type)].Add(sd->name,sd->binding);
|
||||
|
||||
WriteDescriptorSetLayoutBinding(dsl_bind[i],sd);
|
||||
|
||||
++dsl_bind[i];
|
||||
|
||||
++sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MaterialDescriptorManager::~MaterialDescriptorManager()
|
||||
{
|
||||
delete[] all_dslb;
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/io/ConstBufferReader.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@@ -224,7 +225,7 @@ Material *RenderResource::CreateMaterial(const hgl::shadergen::MaterialCreateInf
|
||||
if(sm)
|
||||
{
|
||||
if(smm->Add(sm))
|
||||
vertex_input=new VertexInput(vert->GetInput());
|
||||
vertex_input=new VertexInput(vert->sdm->GetShaderStageIO().input);
|
||||
}
|
||||
|
||||
smm->Add(sm);
|
||||
@@ -252,6 +253,16 @@ Material *RenderResource::CreateMaterial(const hgl::shadergen::MaterialCreateInf
|
||||
smm->Add(sm);
|
||||
}
|
||||
|
||||
MaterialDescriptorManager *mdm=new MaterialDescriptorManager(mci->GetName(),mci->GetMDI().Get());
|
||||
|
||||
Material *mtl=device->CreateMaterial(mci->GetName(),smm,mdm,vertex_input);
|
||||
|
||||
if(!mtl)
|
||||
{
|
||||
delete mdm;
|
||||
delete smm;
|
||||
}
|
||||
|
||||
return mtl;
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -43,6 +43,9 @@ namespace glsl_compiler
|
||||
SPVData * (*CompileFromPath)(const uint32_t stage,const char *shader_filename, const CompileInfo *compile_info);
|
||||
|
||||
void (*Free)(SPVData *);
|
||||
|
||||
SPVParseData *(*ParseSPV)(SPVData *spv_data);
|
||||
void (*FreeParseSPVData)(SPVParseData *);
|
||||
};
|
||||
|
||||
ExternalModule *gsi_module=nullptr;
|
||||
@@ -142,6 +145,17 @@ namespace glsl_compiler
|
||||
gsi->Free(spv_data);
|
||||
}
|
||||
|
||||
SPVParseData *ParseSPV(SPVData *spv_data)
|
||||
{
|
||||
return gsi?gsi->ParseSPV(spv_data):nullptr;
|
||||
}
|
||||
|
||||
void FreeSPVParse(SPVParseData *spv)
|
||||
{
|
||||
if(gsi&&spv)
|
||||
gsi->FreeParseSPVData(spv);
|
||||
}
|
||||
|
||||
SPVData *Compile(const uint32_t type,const char *source)
|
||||
{
|
||||
if(!gsi)
|
||||
|
@@ -75,7 +75,10 @@ namespace glsl_compiler
|
||||
|
||||
uint32_t *spv_data;
|
||||
uint32_t spv_length;
|
||||
};
|
||||
|
||||
struct SPVParseData
|
||||
{
|
||||
ShaderStageIO stage_io;
|
||||
ShaderDescriptorResource resource;
|
||||
ShaderResourceData<PushConstant> push_constant;
|
||||
@@ -92,5 +95,8 @@ namespace glsl_compiler
|
||||
|
||||
SPVData * Compile (const uint32_t type,const char *source);
|
||||
void Free (SPVData *spv_data);
|
||||
|
||||
SPVParseData * ParseSPV(SPVData *spv_data);
|
||||
void FreeSPVParse(SPVParseData *spv);
|
||||
}//namespace glsl_compiler
|
||||
#endif//HGL_GLSL_COMPILER_INCLUDE
|
||||
|
@@ -25,32 +25,6 @@ const DescriptorSetType MaterialDescriptorInfo::GetSetType(const AnsiString &nam
|
||||
return DescriptorSetType::Global;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个描述符,如果它本身存在,则返回false
|
||||
*/
|
||||
ShaderDescriptor *MaterialDescriptorInfo::ShaderDescriptorSet::AddDescriptor(VkShaderStageFlagBits ssb,ShaderDescriptor *new_sd)
|
||||
{
|
||||
ShaderDescriptor *sd;
|
||||
|
||||
if(descriptor_map.Get(new_sd->name,sd))
|
||||
{
|
||||
delete new_sd;
|
||||
sd->stage_flag|=ssb;
|
||||
return(sd);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_sd->set_type=set_type;
|
||||
new_sd->stage_flag=ssb;
|
||||
|
||||
descriptor_map.Add(new_sd->name,new_sd);
|
||||
|
||||
count++;
|
||||
|
||||
return(new_sd);
|
||||
}
|
||||
}
|
||||
|
||||
const UBODescriptor *MaterialDescriptorInfo::AddUBO(VkShaderStageFlagBits ssb,DescriptorSetType set_type,UBODescriptor *sd)
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(set_type);
|
||||
|
@@ -60,9 +60,4 @@ bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
const hgl::graph::ShaderAttributeArray &ShaderCreateInfoVertex::GetInput()const
|
||||
{
|
||||
return spv_data->stage_io.input;
|
||||
}
|
||||
SHADERGEN_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user