[WIP]
This commit is contained in:
parent
806bf5dfdd
commit
2f49e80122
@ -1 +1 @@
|
||||
Subproject commit 78b650ebfec0bbcbff948284ebf54344f8413275
|
||||
Subproject commit b0955107a7d55ec050cb8cec2378ffbacd228096
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VKInterpolation.h>
|
||||
#include<hgl/graph/VKSamplerType.h>
|
||||
@ -242,6 +243,8 @@ namespace hgl
|
||||
|
||||
const char *GetTypename()const;
|
||||
|
||||
bool ParseTypeString(const char *str);
|
||||
|
||||
const uint64 ToCode()const{return svt_code;}
|
||||
const bool FromCode(const uint64 code)
|
||||
{
|
||||
@ -383,6 +386,10 @@ namespace hgl
|
||||
|
||||
ShaderVariable *items;
|
||||
|
||||
public:
|
||||
|
||||
const bool IsEmpty()const{return !items||count<=0;}
|
||||
|
||||
public:
|
||||
|
||||
ShaderVariableArray()
|
||||
@ -510,6 +517,33 @@ namespace hgl
|
||||
hgl_cpy(items,src->items,src->count);
|
||||
return(true);
|
||||
}
|
||||
|
||||
void ToString(AnsiString &output_string)
|
||||
{
|
||||
if(IsEmpty())
|
||||
return;
|
||||
|
||||
const ShaderVariable *sv=items;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
output_string+=" ";
|
||||
|
||||
if(sv->interpolation!=Interpolation::Smooth)
|
||||
{
|
||||
output_string+=InterpolationName[size_t(sv->interpolation)];
|
||||
|
||||
output_string+=" ";
|
||||
}
|
||||
|
||||
output_string+=sv->type.GetTypename();
|
||||
output_string+=" ";
|
||||
output_string+=sv->name;
|
||||
output_string+=";\n";
|
||||
|
||||
++sv;
|
||||
}
|
||||
}
|
||||
};//struct ShaderVariableArray
|
||||
|
||||
using SVArray=ShaderVariableArray;
|
||||
|
@ -52,6 +52,9 @@ protected:
|
||||
virtual bool ProcLayout(){return(true);}
|
||||
|
||||
virtual bool ProcInput(ShaderCreateInfo *);
|
||||
|
||||
virtual bool IsEmptyOutput()const=0;
|
||||
virtual void GetOutputStrcutString(AnsiString &){}
|
||||
virtual bool ProcOutput();
|
||||
|
||||
virtual bool ProcStruct();
|
||||
|
@ -11,10 +11,13 @@ class ShaderCreateInfoFragment:public ShaderCreateInfo
|
||||
|
||||
protected:
|
||||
|
||||
bool IsEmptyOutput()const override{return false;/*这个返回啥无所谓,因为Fragment Shader走自己的ProcOutput*/ }
|
||||
bool ProcOutput() override;
|
||||
|
||||
void AddMaterialInstanceOutput() override{};
|
||||
|
||||
public:
|
||||
|
||||
|
||||
ShaderDescriptorInfo *GetSDI()override{return &fsdi;}
|
||||
|
||||
public:
|
||||
|
@ -13,6 +13,9 @@ class ShaderCreateInfoGeometry:public ShaderCreateInfo
|
||||
uint32_t max_vertices;
|
||||
|
||||
public:
|
||||
|
||||
bool IsEmptyOutput()const override{return gsdi.IsEmptyOutput();}
|
||||
void GetOutputStrcutString(AnsiString &str) override;
|
||||
|
||||
ShaderDescriptorInfo *GetSDI()override{return &gsdi;}
|
||||
|
||||
|
@ -13,6 +13,9 @@ namespace hgl
|
||||
|
||||
bool ProcSubpassInput();
|
||||
bool ProcInput(ShaderCreateInfo *) override;
|
||||
|
||||
bool IsEmptyOutput()const override{return vsdi.IsEmptyOutput();}
|
||||
void GetOutputStrcutString(AnsiString &str) override;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -80,6 +80,9 @@ public:
|
||||
|
||||
IArray &GetInput(){return input;}
|
||||
OArray &GetOutput(){return output;}
|
||||
|
||||
const bool IsEmptyInput()const{return input.IsEmpty();}
|
||||
const bool IsEmptyOutput()const{return output.IsEmpty();}
|
||||
};//class CustomShaderDescriptorInfo
|
||||
|
||||
class VertexShaderDescriptorInfo:public CustomShaderDescriptorInfo<VK_SHADER_STAGE_VERTEX_BIT,VIAArray,VIA,SVArray,ShaderVariable >
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include<hgl/graph/VKSamplerType.h>
|
||||
#include<hgl/graph/VKPrimitiveType.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/graph/mtl/ShaderVariableType.h>
|
||||
|
||||
namespace material_file
|
||||
{
|
||||
@ -14,13 +15,6 @@ namespace material_file
|
||||
|
||||
constexpr size_t SHADER_RESOURCE_NAME_MAX_LENGTH=VERTEX_ATTRIB_NAME_MAX_LENGTH;
|
||||
|
||||
struct ShaderIOAttrib
|
||||
{
|
||||
VAType vat;
|
||||
|
||||
char name[VERTEX_ATTRIB_NAME_MAX_LENGTH];
|
||||
};
|
||||
|
||||
struct MaterialInstanceData
|
||||
{
|
||||
const char *code;
|
||||
@ -61,8 +55,6 @@ namespace material_file
|
||||
const char * code;
|
||||
uint code_length;
|
||||
|
||||
List<ShaderIOAttrib> output;
|
||||
|
||||
List<SamplerData> sampler;
|
||||
|
||||
public:
|
||||
@ -76,6 +68,19 @@ namespace material_file
|
||||
}
|
||||
|
||||
const VkShaderStageFlagBits GetShaderStage()const{return shader_stage;}
|
||||
|
||||
virtual void AddOutput(const ShaderVariable &sv);
|
||||
};
|
||||
|
||||
struct VertexShaderData:public ShaderData
|
||||
{
|
||||
List<ShaderVariable> output;
|
||||
|
||||
VertexShaderData():ShaderData(VK_SHADER_STAGE_VERTEX_BIT){}
|
||||
|
||||
public:
|
||||
|
||||
void AddOutput(const ShaderVariable &sv)override{output.Add(sv);}
|
||||
};
|
||||
|
||||
struct GeometryShaderData:public ShaderData
|
||||
@ -84,9 +89,26 @@ namespace material_file
|
||||
Prim output_prim;
|
||||
uint max_vertices=0;
|
||||
|
||||
List<ShaderVariable> output;
|
||||
|
||||
public:
|
||||
|
||||
using ShaderData::ShaderData;
|
||||
GeometryShaderData():ShaderData(VK_SHADER_STAGE_GEOMETRY_BIT){}
|
||||
|
||||
public:
|
||||
|
||||
void AddOutput(const ShaderVariable &sv)override{output.Add(sv);}
|
||||
};
|
||||
|
||||
struct FragmentShaderData:public ShaderData
|
||||
{
|
||||
List<VIA> output;
|
||||
|
||||
FragmentShaderData():ShaderData(VK_SHADER_STAGE_FRAGMENT_BIT){}
|
||||
|
||||
public:
|
||||
|
||||
void AddOutput(const ShaderVariable &sv)override{}
|
||||
};
|
||||
|
||||
using ShaderDataMap=ObjectMap<VkShaderStageFlagBits,ShaderData>;
|
||||
@ -109,7 +131,7 @@ namespace material_file
|
||||
|
||||
MaterialInstanceData mi{};
|
||||
|
||||
List<ShaderIOAttrib> vi; ///<Vertex Input
|
||||
List<VIA> via; ///<Vertex Input
|
||||
|
||||
UBODataList ubo_list;
|
||||
|
||||
|
@ -346,13 +346,39 @@ namespace
|
||||
}
|
||||
};//struct MaterialInstanceBlockParse
|
||||
|
||||
bool ParseUniformAttrib(ShaderIOAttrib *ua,const char *str)
|
||||
bool ParseVertexInputAttrib(VIA *via,const char *str)
|
||||
{
|
||||
const char *sp;
|
||||
|
||||
while(*str==' '||*str=='\t')++str;
|
||||
|
||||
if(!ParseVertexAttribType(&(ua->vat),str))
|
||||
VAType vat;
|
||||
|
||||
if(!ParseVertexAttribType(&(vat),str))
|
||||
return(false);
|
||||
|
||||
via->basetype=uint8(vat.basetype);
|
||||
via->vec_size=vat.vec_size;
|
||||
|
||||
while(*str!=' '&&*str!='\t')++str;
|
||||
while(*str==' '||*str=='\t')++str;
|
||||
|
||||
sp=str;
|
||||
|
||||
while(hgl::iscodechar(*str))++str;
|
||||
|
||||
hgl::strcpy(via->name,SHADER_RESOURCE_NAME_MAX_LENGTH,sp,str-sp);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool ParseUniformAttrib(ShaderVariable *sv,const char *str)
|
||||
{
|
||||
const char *sp;
|
||||
|
||||
while(*str==' '||*str=='\t')++str;
|
||||
|
||||
if(!sv->type.ParseTypeString(str))
|
||||
return(false);
|
||||
|
||||
while(*str!=' '&&*str!='\t')++str;
|
||||
@ -362,20 +388,20 @@ namespace
|
||||
|
||||
while(hgl::iscodechar(*str))++str;
|
||||
|
||||
hgl::strcpy(ua->name,SHADER_RESOURCE_NAME_MAX_LENGTH,sp,str-sp);
|
||||
hgl::strcpy(sv->name,SHADER_RESOURCE_NAME_MAX_LENGTH,sp,str-sp);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
struct VertexInputBlockParse:public TextParse
|
||||
{
|
||||
List<ShaderIOAttrib> *vi_list=nullptr;
|
||||
List<VIA> *via_list=nullptr;
|
||||
|
||||
public:
|
||||
|
||||
VertexInputBlockParse(List<ShaderIOAttrib> *ual)
|
||||
VertexInputBlockParse(List<VIA> *ual)
|
||||
{
|
||||
vi_list=ual;
|
||||
via_list=ual;
|
||||
}
|
||||
|
||||
bool OnLine(char *text,const int len) override
|
||||
@ -383,10 +409,10 @@ namespace
|
||||
if(!text||!*text||len<=0)
|
||||
return(false);
|
||||
|
||||
ShaderIOAttrib ua;
|
||||
VIA via;
|
||||
|
||||
if(ParseUniformAttrib(&ua,text))
|
||||
vi_list->Add(ua);
|
||||
if(ParseVertexInputAttrib(&via,text))
|
||||
via_list->Add(via);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -434,10 +460,10 @@ namespace
|
||||
return(true);
|
||||
}
|
||||
|
||||
ShaderIOAttrib ua;
|
||||
ShaderVariable sv;
|
||||
|
||||
if(ParseUniformAttrib(&ua,text))
|
||||
shader_data->output.Add(ua);
|
||||
if(ParseUniformAttrib(&sv,text))
|
||||
shader_data->AddOutput(sv);
|
||||
}
|
||||
|
||||
if(hgl::stricmp(text,"Code",4)==0)
|
||||
|
@ -118,20 +118,6 @@ bool ShaderCreateInfo::AddSampler(DescriptorSetType type,const SamplerDescriptor
|
||||
return GetSDI()->AddSampler(type,sd);
|
||||
}
|
||||
|
||||
//int ShaderCreateInfo::AddOutput(const ShaderVariableType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth)
|
||||
//{
|
||||
// VertexInputAttribute *ss=new VertexInputAttribute;
|
||||
//
|
||||
// hgl::strcpy(ss->name,sizeof(ss->name),name.c_str());
|
||||
//
|
||||
// ss->basetype =(uint8)type.base_type;
|
||||
// ss->vec_size = type.vec_size;
|
||||
// ss->interpolation = inter;
|
||||
//
|
||||
// return sdi->AddOutput(ss);
|
||||
//
|
||||
//}
|
||||
|
||||
void ShaderCreateInfo::SetMaterialInstance(UBODescriptor *ubo,const AnsiString &mi)
|
||||
{
|
||||
AddUBO(DescriptorSetType::PerMaterial,ubo);
|
||||
@ -166,42 +152,17 @@ bool ShaderCreateInfo::ProcInput(ShaderCreateInfo *last_sc)
|
||||
return(true);
|
||||
}
|
||||
|
||||
void ToStringList(AnsiString &output_struct,const SVArray &sv_array)
|
||||
{
|
||||
const ShaderVariable *sv=sv_array.items;
|
||||
|
||||
for(uint i=0;i<sv_array.count;i++)
|
||||
{
|
||||
output_struct+=" ";
|
||||
|
||||
if(sv->interpolation!=Interpolation::Smooth)
|
||||
{
|
||||
output_struct+=InterpolationName[size_t(sv->interpolation)];
|
||||
|
||||
output_struct+=" ";
|
||||
}
|
||||
|
||||
output_struct+=sv->type.GetTypename();
|
||||
output_struct+=" ";
|
||||
output_struct+=sv->name;
|
||||
output_struct+=";\n";
|
||||
|
||||
++sv;
|
||||
}
|
||||
}
|
||||
|
||||
bool ShaderCreateInfo::ProcOutput()
|
||||
{
|
||||
output_struct.Clear();
|
||||
|
||||
const SVArray &sv_array=GetSDI()->GetOutput();
|
||||
|
||||
if(sv_array.count<=0)return(true);
|
||||
if(IsEmptyOutput())
|
||||
return(true);
|
||||
|
||||
output_struct=GetShaderStageName(shader_stage);
|
||||
output_struct+="_Output\n{\n";
|
||||
|
||||
ToStringList(output_struct,sv_array);
|
||||
GetOutputStrcutString(output_struct);
|
||||
|
||||
output_struct+="}";
|
||||
|
||||
@ -214,7 +175,7 @@ bool ShaderCreateInfo::ProcOutput()
|
||||
|
||||
bool ShaderCreateInfo::ProcStruct()
|
||||
{
|
||||
const AnsiStringList &struct_list=sdi->GetStructList();
|
||||
const AnsiStringList &struct_list=GetSDI()->GetStructList();
|
||||
|
||||
AnsiString codes;
|
||||
|
||||
@ -246,7 +207,7 @@ bool ShaderCreateInfo::ProcMI()
|
||||
|
||||
bool ShaderCreateInfo::ProcUBO()
|
||||
{
|
||||
auto ubo_list=sdi->GetUBOList();
|
||||
auto ubo_list=GetSDI()->GetUBOList();
|
||||
|
||||
const int count=ubo_list.GetCount();
|
||||
|
||||
@ -290,7 +251,7 @@ bool ShaderCreateInfo::ProcSSBO()
|
||||
|
||||
bool ShaderCreateInfo::ProcConstantID()
|
||||
{
|
||||
auto const_list=sdi->GetConstList();
|
||||
auto const_list=GetSDI()->GetConstList();
|
||||
|
||||
const int count=const_list.GetCount();
|
||||
|
||||
@ -320,7 +281,7 @@ bool ShaderCreateInfo::ProcConstantID()
|
||||
|
||||
bool ShaderCreateInfo::ProcSampler()
|
||||
{
|
||||
auto sampler_list=sdi->GetSamplerList();
|
||||
auto sampler_list=GetSDI()->GetSamplerList();
|
||||
|
||||
const int count=sampler_list.GetCount();
|
||||
|
||||
|
@ -37,6 +37,11 @@ namespace hgl
|
||||
|
||||
return gsdi.AddOutput(sv);
|
||||
}
|
||||
|
||||
void ShaderCreateInfoGeometry::GetOutputStrcutString(AnsiString &str)
|
||||
{
|
||||
gsdi.GetOutput().ToString(str);
|
||||
}
|
||||
|
||||
bool ShaderCreateInfoGeometry::ProcLayout()
|
||||
{
|
||||
|
@ -12,14 +12,6 @@ void ShaderCreateInfoVertex::AddMaterialInstanceOutput()
|
||||
{
|
||||
AddOutput(SVT_UINT,mtl::func::MI_ID_OUTPUT,Interpolation::Flat);
|
||||
AddFunction(mtl::func::MF_HandoverMI_VS);
|
||||
}
|
||||
else
|
||||
if(shader_stage==VK_SHADER_STAGE_GEOMETRY_BIT)
|
||||
{
|
||||
AddFunction(MF_HandoverMI_GS);
|
||||
}
|
||||
//else
|
||||
//AddFunction(MF_HandoverMI_OTHER);
|
||||
}
|
||||
|
||||
int ShaderCreateInfoVertex::AddInput(const VAType &type,const AnsiString &name,const VkVertexInputRate input_rate,const VertexInputGroup &group)
|
||||
@ -140,4 +132,9 @@ bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void ShaderCreateInfoVertex::GetOutputStrcutString(AnsiString &str)
|
||||
{
|
||||
vsdi.GetOutput().ToString(str);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -99,4 +99,171 @@ const char *ShaderVariableType::GetTypename()const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool ShaderVariableType::ParseTypeString(const char *str)
|
||||
{
|
||||
if(!str||!*str)
|
||||
return(false);
|
||||
|
||||
if(str[0]=='b')
|
||||
{
|
||||
if(str[1]=='o'&&str[2]=='o'&&str[3]=='l')
|
||||
{
|
||||
base_type=SVBaseType::Scalar;
|
||||
scalar.type=VABaseType::Bool;
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(str[1]=='v'&&str[2]=='e'&&str[3]=='c')
|
||||
{
|
||||
base_type=SVBaseType::Vector;
|
||||
vector.type=VABaseType::Bool;
|
||||
vector.vec_size=str[4]-'0';
|
||||
return(vector.vec_size>=2&&vector.vec_size<=4);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(str[1]=='i')
|
||||
{
|
||||
if(str[2]=='n'&&str[3]=='t')
|
||||
{
|
||||
base_type=SVBaseType::Scalar;
|
||||
scalar.type=VABaseType::Int;
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(str[2]=='v'&&str[3]=='e'&&str[4]=='c')
|
||||
{
|
||||
base_type=SVBaseType::Vector;
|
||||
vector.type=VABaseType::Int;
|
||||
vector.vec_size=str[5]-'0';
|
||||
return(vector.vec_size>=2&&vector.vec_size<=4);
|
||||
}
|
||||
|
||||
if(str[1]=='m'&&str[2]=='a'&&str[3]=='g'&&str[4]=='e')
|
||||
{
|
||||
int name_len=5;
|
||||
while(iscodechar(str[name_len]))
|
||||
++name_len;
|
||||
|
||||
base_type=SVBaseType::Image;
|
||||
image.type=ParseShaderImageType(str,name_len);
|
||||
return(image.type!=ShaderImageType::Error);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(str[1]=='u')
|
||||
{
|
||||
if(str[2]=='i'&&str[3]=='n'&&str[4]=='t')
|
||||
{
|
||||
base_type=SVBaseType::Scalar;
|
||||
scalar.type=VABaseType::UInt;
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(str[2]=='v'&&str[3]=='e'&&str[4]=='c')
|
||||
{
|
||||
base_type=SVBaseType::Vector;
|
||||
vector.type=VABaseType::UInt;
|
||||
vector.vec_size=str[5]-'0';
|
||||
return(vector.vec_size>=2&&vector.vec_size<=4);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(str[1]=='f')
|
||||
{
|
||||
if(str[2]=='l'&&str[3]=='o'&&str[4]=='a'&&str[5]=='t')
|
||||
{
|
||||
base_type=SVBaseType::Scalar;
|
||||
scalar.type=VABaseType::Float;
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(str[0]=='v')
|
||||
{
|
||||
if(str[1]=='e'&&str[2]=='c')
|
||||
{
|
||||
base_type=SVBaseType::Vector;
|
||||
vector.type=VABaseType::Float;
|
||||
vector.vec_size=str[3]-'0';
|
||||
return(vector.vec_size>=2&&vector.vec_size<=4);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(str[1]=='d')
|
||||
{
|
||||
if(str[2]=='o'&&str[3]=='u'&&str[4]=='b'&&str[5]=='l'&&str[6]=='e')
|
||||
{
|
||||
base_type=SVBaseType::Scalar;
|
||||
scalar.type=VABaseType::Double;
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(str[2]=='m'&&str[3]=='a'&&str[4]=='t')
|
||||
{
|
||||
base_type=SVBaseType::Matrix;
|
||||
matrix.type=VABaseType::Double;
|
||||
matrix.n=str[5]-'0';
|
||||
|
||||
if(str[6]=='x')
|
||||
{
|
||||
matrix.m=str[7]-'0';
|
||||
return(matrix.m>=2&&matrix.m<=4);
|
||||
}
|
||||
|
||||
matrix.m=0;
|
||||
return(matrix.n>=2&&matrix.n<=4);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(str[0]=='m')
|
||||
{
|
||||
if(str[1]=='a'&&str[2]=='t')
|
||||
{
|
||||
base_type=SVBaseType::Matrix;
|
||||
matrix.type=VABaseType::Float;
|
||||
matrix.n=str[3]-'0';
|
||||
|
||||
if(str[4]=='x')
|
||||
{
|
||||
matrix.m=str[5]-'0';
|
||||
return(matrix.m>=2&&matrix.m<=4);
|
||||
}
|
||||
|
||||
matrix.m=0;
|
||||
return(matrix.n>=2&&matrix.n<=4);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(hgl::strcmp(str,"sampler",7)==0)
|
||||
{
|
||||
int name_len=7;
|
||||
while(iscodechar(str[name_len]))
|
||||
++name_len;
|
||||
|
||||
base_type=SVBaseType::Sampler;
|
||||
sampler.type=ParseSamplerType(str,name_len);
|
||||
return(sampler.type!=SamplerType::Error);
|
||||
}
|
||||
|
||||
if(hgl::strcmp(str,"atomic_uint",11)==0)
|
||||
{
|
||||
base_type=SVBaseType::AtomicCounter;
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user