removed source codes about "Load Material file"

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-06-05 17:00:22 +08:00
parent f4a8406ad8
commit d17932c7a4
5 changed files with 1 additions and 270 deletions

View File

@ -97,11 +97,9 @@ public: //Material
const ShaderModule *CreateShaderModule(const OSString &filename,VkShaderStageFlagBits shader_stage,const uint32_t *spv_data,const size_t spv_size);
Material * CreateMaterial(const OSString &);
Material * CreateMaterial(const mtl::MaterialCreateInfo *);
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
MaterialInstance * CreateMaterialInstance(const OSString &,const VILConfig *vil_cfg=nullptr);
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
Primitive * CreatePrimitive(const uint32_t vertex_count=0);

View File

@ -62,16 +62,6 @@ MaterialInstance *RenderResource::CreateMaterialInstance(Material *mtl,const VIL
return mi;
}
MaterialInstance *RenderResource::CreateMaterialInstance(const OSString &mtl_filename,const VILConfig *vil_cfg)
{
Material *mtl=this->CreateMaterial(mtl_filename);
if(!mtl)
return(nullptr);
return CreateMaterialInstance(mtl,vil_cfg);
}
MaterialInstance *RenderResource::CreateMaterialInstance(const mtl::MaterialCreateInfo *mci,const VILConfig *vil_cfg)
{
Material *mtl=this->CreateMaterial(mci);

View File

@ -12,7 +12,6 @@
#include<hgl/shadergen/ShaderDescriptorInfo.h>
VK_NAMESPACE_BEGIN
const ShaderModule *RenderResource::CreateShaderModule(const OSString &filename,VkShaderStageFlagBits shader_stage,const uint32_t *spv_data,const size_t spv_size)
{
if(!device)return(nullptr);
@ -45,160 +44,6 @@ const ShaderModule *RenderResource::CreateShaderModule(const OSString &filename,
return sm;
}
void LoadShaderDescriptor(io::ConstBufferReader &cbr,ShaderDescriptor *sd_list,const uint count,const uint8 ver)
{
ShaderDescriptor *sd=sd_list;
for(uint i=0;i<count;i++)
{
cbr.CastRead<uint8>(sd->desc_type);
cbr.ReadTinyString(sd->name);
if(ver==3)
cbr.CastRead<uint8>(sd->set_type);
else
if(ver==2) //以下是旧的,未来不用了,现仅保证能运行
{
if(sd->name[0]=='g')sd->set_type=DescriptorSetType::Global;else
//if(sd->name[0]=='m')sd->set_type=DescriptorSetType::PerMaterial;else
//if(sd->name[0]=='r')sd->set_type=DescriptorSetType::PerObject;else
sd->set_type=DescriptorSetType::PerMaterial;
}
cbr.Read(sd->set);
cbr.Read(sd->binding);
cbr.Read(sd->stage_flag);
//if(sd->set_type>=DescriptorSetType::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;
//}
++sd;
}
}
ShaderResource *LoadShaderResource(io::ConstBufferReader &cbr);
Material *RenderResource::CreateMaterial(const OSString &filename)
{
Material *mtl;
if(material_by_name.Get(filename,mtl))
return mtl;
constexpr char MaterialFileHeader[]=u8"Material\x1A";
constexpr uint MaterialFileHeaderLength=sizeof(MaterialFileHeader)-1;
int64 filesize;
uint8 *filedata=(uint8 *)filesystem::LoadFileToMemory(filename+OS_TEXT(".material"),filesize);
if(!filedata)
{
material_by_name.Add(filename,nullptr);
return(nullptr);
}
AutoDeleteArray<uint8> origin_filedata(filedata,filesize);
if(filesize<MaterialFileHeaderLength)
return(nullptr);
io::ConstBufferReader cbr(filedata,filesize);
if(memcmp(cbr.CurPointer(),MaterialFileHeader,MaterialFileHeaderLength)!=0)
return(nullptr);
cbr.Skip(MaterialFileHeaderLength);
uint8 ver;
cbr.Read(ver);
if(ver<2||ver>3)
return(nullptr);
uint32_t shader_bits;
cbr.Read(shader_bits);
const uint count=GetShaderCountByBits(shader_bits);
uint32_t size;
ShaderResource *sr;
const ShaderModule *sm;
bool result=true;
ShaderModuleMap *smm=new ShaderModuleMap;
VertexInput *vertex_input=nullptr;
OSString shader_name;
for(uint i=0;i<count;i++)
{
cbr.Read(size);
sr=LoadShaderResource(io::ConstBufferReader(cbr,size)); //有一个stage output没读放弃了所以不能直接用上一级的cbr
cbr.Skip(size);
if(sr)
{
shader_name=filename+OS_TEXT("?")+ToOSString(sr->GetStageName());
sm=CreateShaderModule(shader_name,sr->GetStage(),sr->GetSPVData(),sr->GetSPVSize());
if(sm)
{
if(smm->Add(sm))
{
if(sr->GetStage()==VK_SHADER_STAGE_VERTEX_BIT)
vertex_input=new VertexInput(sr->GetInputs());
continue;
}
}
}
result=false;
break;
}
const UTF8String mtl_name=ToUTF8String(filename);
MaterialDescriptorManager *desc_manager=nullptr;
{
uint8 count;
cbr.Read(count);
if(count>0)
{
ShaderDescriptor *sd_list=new ShaderDescriptor[count];
LoadShaderDescriptor(cbr,sd_list,count,ver);
desc_manager=new MaterialDescriptorManager(mtl_name,sd_list,count);
delete[] sd_list;
}
}
if(result&&vertex_input)
{
mtl=device->CreateMaterial(mtl_name,smm,desc_manager,vertex_input);
Add(mtl);
}
else
{
SAFE_CLEAR(desc_manager);
delete smm;
mtl=nullptr;
}
material_by_name.Add(filename,mtl);
return(mtl);
}
Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
{
if(!mci)
@ -276,6 +121,6 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
}
material_by_name.Add(mtl_name,mtl);
return mtl;
return mtl;
}
VK_NAMESPACE_END

View File

@ -5,39 +5,6 @@
#include<hgl/io/ConstBufferReader.h>
VK_NAMESPACE_BEGIN
namespace
{
ObjectMap<OSString,ShaderResource> shader_resource_by_filename;
const bool LoadShaderStageAttributes(ShaderAttributeArray &sa_array,io::ConstBufferReader &cbr)
{
uint count;
cbr.CastRead<uint8>(count);
if(count<=0)
return(false);
Init(&sa_array,count);
ShaderAttribute *ss=sa_array.items;
for(uint i=0;i<count;i++)
{
cbr.Read(ss->location);
cbr.CastRead<uint8>(ss->basetype);
cbr.CastRead<uint8>(ss->vec_size);
cbr.ReadTinyString(ss->name);
++ss;
}
return true;
}
}//namespcae
ShaderResource::ShaderResource(const VkShaderStageFlagBits &flag,const uint32_t *sd,const uint32 size)
{
stage_flag=flag;
@ -85,22 +52,4 @@ VK_NAMESPACE_BEGIN
return -1;
}
ShaderResource *LoadShaderResource(io::ConstBufferReader &cbr)
{
VkShaderStageFlagBits flag;
uint32 spv_size;
cbr.CastRead<uint32>(flag);
cbr.Read(spv_size);
ShaderResource *sr=new ShaderResource(flag,(const uint32_t *)cbr.CurPointer(),spv_size);
cbr.Skip(spv_size);
LoadShaderStageAttributes(sr->GetInputs(),cbr);
// LoadShaderStageAttributes(sr->GetStageOutputs(),cbr);
return sr;
}
VK_NAMESPACE_END

View File

@ -109,55 +109,4 @@ void ShaderDescriptorInfo::SetPushConstant(const UTF8String name,uint8_t offset,
push_constant.offset=offset;
push_constant.size =size;
}
#ifdef _DEBUG
void ShaderDescriptorInfo::DebugOutput(int index)
{
UTF8String name=GetStageName();
LOG_INFO(UTF8String::numberOf(index)+": "+name+" shader");
if(stage_io.input.count>0)
{
LOG_INFO("\tStage Input "+UTF8String::numberOf(stage_io.input.count));
const ShaderAttribute *ss=stage_io.input.items;
for(uint i=0;i<stage_io.input.count;i++)
{
LOG_INFO("\t\tlayout(location="+UTF8String::numberOf(ss->location)+") in "+GetShaderAttributeTypename(ss)+"\t"+UTF8String(ss->name));
++ss;
}
}
if(stage_io.output.count>0)
{
LOG_INFO("\tStage Output "+UTF8String::numberOf(stage_io.output.count));
const ShaderAttribute *ss=stage_io.output.items;
for(uint i=0;i<stage_io.output.count;i++)
{
LOG_INFO("\t\tlayout(location="+UTF8String::numberOf(ss->location)+") out "+GetShaderAttributeTypename(ss)+"\t"+UTF8String(ss->name));
++ss;
}
}
if(ubo_list.GetCount()>0)
{
LOG_INFO("\tUBO "+UTF8String::numberOf(ubo_list.GetCount()));
for(auto *ubo:ubo_list)
LOG_INFO("\t\tlayout(set="+UTF8String::numberOf(ubo->set)+",binding="+UTF8String::numberOf(ubo->binding)+") uniform "+ubo->type+"\t"+ubo->type);
}
if(sampler_list.GetCount()>0)
{
LOG_INFO("\tSampler "+UTF8String::numberOf(sampler_list.GetCount()));
for(auto *ubo:ubo_list)
LOG_INFO("\t\tlayout(set="+UTF8String::numberOf(ubo->set)+",binding="+UTF8String::numberOf(ubo->binding)+") uniform "+ubo->type+"\t"+ubo->type);
}
}
#endif//_DEBUG
}}//namespace hgl::graph