[WIP] next step is ShaderCreateInfo::ProcOutput
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VKInterpolation.h>
|
||||
#include<hgl/graph/VKSamplerType.h>
|
||||
#include<hgl/graph/VKImageType.h>
|
||||
#include<hgl/CompOperator.h>
|
||||
@@ -13,13 +14,12 @@ namespace hgl
|
||||
{
|
||||
Scalar=0,
|
||||
Vector,
|
||||
Materix,
|
||||
Matrix,
|
||||
Sampler,
|
||||
Image,
|
||||
AtomicCounter,
|
||||
ImplicitConversion,
|
||||
|
||||
ENUM_CLASS_RANGE(Scalar,Materix)
|
||||
ENUM_CLASS_RANGE(Scalar,AtomicCounter)
|
||||
};//enum class ShaderVariableBaseType
|
||||
|
||||
using SVBaseType=ShaderVariableBaseType;
|
||||
@@ -123,7 +123,7 @@ namespace hgl
|
||||
{
|
||||
svt_code=0;
|
||||
|
||||
base_type=SVBaseType::Materix;
|
||||
base_type=SVBaseType::Matrix;
|
||||
|
||||
matrix.type=vabt;
|
||||
matrix.n=col;
|
||||
@@ -170,7 +170,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(base_type==SVBaseType::Materix)
|
||||
if(base_type==SVBaseType::Matrix)
|
||||
{
|
||||
if(matrix.m==0)
|
||||
{
|
||||
@@ -216,7 +216,7 @@ namespace hgl
|
||||
return int(vector.type)-int(svt.vector.type);
|
||||
}
|
||||
|
||||
if(base_type==SVBaseType::Materix)
|
||||
if(base_type==SVBaseType::Matrix)
|
||||
{
|
||||
off=int(matrix.type)-int(svt.matrix.type);
|
||||
|
||||
@@ -240,6 +240,8 @@ namespace hgl
|
||||
|
||||
CompOperator(const ShaderVariableType &,Comp)
|
||||
|
||||
const char *GetTypename()const;
|
||||
|
||||
const uint64 ToCode()const{return svt_code;}
|
||||
const bool FromCode(const uint64 code)
|
||||
{
|
||||
@@ -366,5 +368,150 @@ namespace hgl
|
||||
|
||||
const SVType SVT_Image2DMS(ShaderImageType::Image2DMS,1);
|
||||
const SVType SVT_Image2DMSArray(ShaderImageType::Image2DMSArray,1);
|
||||
|
||||
struct ShaderVariable
|
||||
{
|
||||
char name[VERTEX_ATTRIB_NAME_MAX_LENGTH];
|
||||
uint location;
|
||||
SVType type;
|
||||
Interpolation interpolation; //插值方式
|
||||
};
|
||||
|
||||
struct ShaderVariableArray
|
||||
{
|
||||
uint count;
|
||||
|
||||
ShaderVariable *items;
|
||||
|
||||
public:
|
||||
|
||||
ShaderVariableArray()
|
||||
{
|
||||
count=0;
|
||||
items=nullptr;
|
||||
}
|
||||
|
||||
~ShaderVariableArray()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
int Comp(const ShaderVariableArray *sva)const
|
||||
{
|
||||
if(!sva)
|
||||
return 1;
|
||||
|
||||
int off=count-sva->count;
|
||||
if(off)return off;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
off=items[i].location-sva->items[i].location;
|
||||
if(off)
|
||||
return off;
|
||||
|
||||
if(items[i].type.ToCode()>sva->items[i].type.ToCode())
|
||||
return 1;
|
||||
|
||||
//ToCode返回的是uint64,可能差值超大,所以不能直接用-的结果
|
||||
|
||||
if(items[i].type.ToCode()<sva->items[i].type.ToCode())
|
||||
return -1;
|
||||
|
||||
off=int(items[i].interpolation)-int(sva->items[i].interpolation);
|
||||
if(off)
|
||||
return off;
|
||||
|
||||
off=hgl::strcmp(items[i].name,sva->items[i].name);
|
||||
if(off)
|
||||
return off;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Comp(const ShaderVariableArray &sva)const{return Comp(&sva);}
|
||||
|
||||
CompOperator(const ShaderVariableArray *,Comp)
|
||||
CompOperator(const ShaderVariableArray &,Comp)
|
||||
|
||||
bool Init(const uint c=0)
|
||||
{
|
||||
if(items)
|
||||
return(false);
|
||||
|
||||
if(c>0)
|
||||
{
|
||||
count=c;
|
||||
items=array_alloc<ShaderVariable>(count);
|
||||
}
|
||||
else
|
||||
{
|
||||
count=0;
|
||||
items=nullptr;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool IsMember(const char *name)const
|
||||
{
|
||||
if(count<=0)
|
||||
return(false);
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
if(hgl::strcmp(items[i].name,name)==0)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool Add(ShaderVariable &sv)
|
||||
{
|
||||
if(IsMember(sv.name))
|
||||
return(false);
|
||||
|
||||
sv.location=count;
|
||||
|
||||
if(!items)
|
||||
{
|
||||
items=array_alloc<ShaderVariable>(1);
|
||||
count=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
++count;
|
||||
items=array_realloc(items,count);
|
||||
}
|
||||
|
||||
hgl_cpy(items[count-1],sv);
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
if(items)
|
||||
{
|
||||
array_free(items);
|
||||
items=nullptr;
|
||||
}
|
||||
|
||||
count=0;
|
||||
}
|
||||
|
||||
bool Clone(const ShaderVariableArray *src)
|
||||
{
|
||||
if(!src)
|
||||
return(false);
|
||||
|
||||
if(!Init(src->count))
|
||||
return(false);
|
||||
|
||||
hgl_cpy(items,src->items,src->count);
|
||||
return(true);
|
||||
}
|
||||
};//struct ShaderVariableArray
|
||||
|
||||
using SVArray=ShaderVariableArray;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKInterpolation.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/graph/mtl/ShaderVariableType.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
|
||||
@@ -15,6 +16,7 @@ class MaterialDescriptorInfo;
|
||||
class ShaderDescriptorInfo;
|
||||
|
||||
struct UBODescriptor;
|
||||
struct SamplerDescriptor;
|
||||
|
||||
class ShaderCreateInfo
|
||||
{
|
||||
@@ -28,8 +30,8 @@ protected:
|
||||
|
||||
AnsiStringList define_macro_list;
|
||||
AnsiStringList define_value_list;
|
||||
uint32_t define_macro_max_length;
|
||||
uint32_t define_value_max_length;
|
||||
int define_macro_max_length;
|
||||
int define_value_max_length;
|
||||
|
||||
AnsiString output_struct;
|
||||
|
||||
@@ -49,7 +51,6 @@ protected:
|
||||
virtual bool ProcDefine();
|
||||
virtual bool ProcLayout(){return(true);}
|
||||
|
||||
virtual bool ProcSubpassInput();
|
||||
virtual bool ProcInput(ShaderCreateInfo *);
|
||||
virtual bool ProcOutput();
|
||||
|
||||
@@ -66,25 +67,28 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
ShaderDescriptorInfo *sdi;
|
||||
|
||||
virtual ShaderDescriptorInfo *GetSDI()=0;
|
||||
const VkShaderStageFlagBits GetShaderStage()const{return shader_stage;}
|
||||
|
||||
protected:
|
||||
|
||||
void Init(ShaderDescriptorInfo *sdi,MaterialDescriptorInfo *m);
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorInfo *m);
|
||||
ShaderCreateInfo();
|
||||
virtual ~ShaderCreateInfo();
|
||||
|
||||
bool AddDefine(const AnsiString &m,const AnsiString &v);
|
||||
|
||||
int AddOutput(const graph::VAType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
//int AddOutput(const ShaderVariableType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
void AddStruct(const AnsiString &);
|
||||
bool AddUBO(DescriptorSetType type,const UBODescriptor *sd);
|
||||
bool AddSampler(DescriptorSetType type,const SamplerDescriptor *sd);
|
||||
|
||||
void AddFunction(const char *str){function_list.Add(str);}
|
||||
|
||||
void SetMaterialInstance(UBODescriptor *,const AnsiString &);
|
||||
void AddMaterialInstanceOutput();
|
||||
virtual void AddMaterialInstanceOutput()=0;
|
||||
|
||||
void SetMain(const AnsiString &str){main_function=str;}
|
||||
void SetMain(const char *str,const int len)
|
||||
|
@@ -1,16 +1,28 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
|
||||
class ShaderCreateInfoFragment:public ShaderCreateInfo
|
||||
{
|
||||
FragmentShaderDescriptorInfo fsdi;
|
||||
|
||||
protected:
|
||||
|
||||
bool ProcOutput() override;
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoFragment(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_FRAGMENT_BIT,m){}
|
||||
ShaderDescriptorInfo *GetSDI()override{return &fsdi;}
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoFragment(MaterialDescriptorInfo *m):ShaderCreateInfo(){ShaderCreateInfo::Init(&fsdi,m);}
|
||||
~ShaderCreateInfoFragment()=default;
|
||||
|
||||
int AddOutput(const graph::VAType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
};
|
||||
}}//namespace hgl::graph
|
@@ -1,20 +1,30 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
class ShaderCreateInfoGeometry:public ShaderCreateInfo
|
||||
{
|
||||
GeometryShaderDescriptorInfo gsdi;
|
||||
|
||||
AnsiString input_prim;
|
||||
AnsiString output_prim;
|
||||
uint32_t max_vertices;
|
||||
uint32_t max_vertices;
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoGeometry(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_GEOMETRY_BIT,m){}
|
||||
~ShaderCreateInfoGeometry()=default;
|
||||
ShaderDescriptorInfo *GetSDI()override{return &gsdi;}
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoGeometry(MaterialDescriptorInfo *m):ShaderCreateInfo(){ShaderCreateInfo::Init(&gsdi,m);}
|
||||
~ShaderCreateInfoGeometry()override=default;
|
||||
|
||||
bool SetGeom(const Prim &ip,const Prim &op,const uint32_t mv);
|
||||
|
||||
int AddOutput(const ShaderVariableType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
void AddMaterialInstanceOutput() override;
|
||||
|
||||
bool ProcLayout() override;
|
||||
};
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@@ -9,17 +9,27 @@ namespace hgl
|
||||
{
|
||||
class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||
{
|
||||
VertexShaderDescriptorInfo vsdi;
|
||||
|
||||
bool ProcSubpassInput();
|
||||
bool ProcInput(ShaderCreateInfo *) override;
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *);
|
||||
~ShaderCreateInfoVertex()=default;
|
||||
ShaderDescriptorInfo *GetSDI()override{return &vsdi;}
|
||||
|
||||
public:
|
||||
|
||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *m):ShaderCreateInfo(){ShaderCreateInfo::Init(&vsdi,m);}
|
||||
~ShaderCreateInfoVertex()override=default;
|
||||
|
||||
int AddInput(const graph::VAType &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
int AddInput(const AnsiString &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
|
||||
int hasInput(const char *);
|
||||
|
||||
int AddOutput(const SVType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
void AddMaterialInstanceOutput() override;
|
||||
|
||||
void AddAssign();
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
#include<hgl/graph/mtl/ShaderVariableType.h>
|
||||
#include<hgl/shadergen/MaterialDescriptorInfo.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
@@ -18,9 +19,9 @@ using SubpassInputDescriptorList=ObjectList<SubpassInputDescriptor>;
|
||||
*/
|
||||
class ShaderDescriptorInfo
|
||||
{
|
||||
VkShaderStageFlagBits stage_flag;
|
||||
protected:
|
||||
|
||||
ShaderStageIO stage_io;
|
||||
VkShaderStageFlagBits stage_flag;
|
||||
|
||||
AnsiStringList struct_list; //用到的结构列表
|
||||
|
||||
@@ -29,22 +30,19 @@ class ShaderDescriptorInfo
|
||||
SamplerDescriptorList sampler_list;
|
||||
|
||||
ConstValueDescriptorList const_value_list;
|
||||
SubpassInputDescriptorList subpass_input;
|
||||
|
||||
ShaderPushConstant push_constant;
|
||||
|
||||
public:
|
||||
|
||||
ShaderDescriptorInfo(VkShaderStageFlagBits);
|
||||
~ShaderDescriptorInfo()=default;
|
||||
virtual ~ShaderDescriptorInfo()=default;
|
||||
|
||||
const VkShaderStageFlagBits GetStageFlag()const { return stage_flag; }
|
||||
const VkShaderStageFlagBits GetShaderStage()const { return stage_flag; }
|
||||
const AnsiString GetStageName()const { return AnsiString(GetShaderStageName(stage_flag)); }
|
||||
|
||||
public:
|
||||
|
||||
const ShaderStageIO & GetShaderStageIO()const{return stage_io;}
|
||||
|
||||
const AnsiStringList & GetStructList()const{return struct_list;}
|
||||
|
||||
const UBODescriptorList & GetUBOList()const{return ubo_list;}
|
||||
@@ -52,22 +50,57 @@ public:
|
||||
|
||||
const ConstValueDescriptorList & GetConstList()const{return const_value_list;}
|
||||
|
||||
const SubpassInputDescriptorList & GetSubpassInputList()const{return subpass_input;}
|
||||
|
||||
public:
|
||||
|
||||
bool AddInput(VertexInputAttribute *);
|
||||
bool AddOutput(VertexInputAttribute *);
|
||||
|
||||
bool hasInput(const char *)const; ///<是否有指定输入
|
||||
|
||||
void AddStruct(const AnsiString &);
|
||||
bool AddUBO(DescriptorSetType type,const UBODescriptor *sd);
|
||||
bool AddSampler(DescriptorSetType type,const SamplerDescriptor *sd);
|
||||
|
||||
bool AddConstValue(ConstValueDescriptor *sd);
|
||||
bool AddSubpassInput(const AnsiString name,uint8_t index);
|
||||
bool AddConstValue(ConstValueDescriptor *sd);
|
||||
|
||||
void SetPushConstant(const AnsiString name,uint8_t offset,uint8_t size);
|
||||
};//class ShaderDescriptorInfo
|
||||
|
||||
template<VkShaderStageFlagBits SS,typename IArray,typename I,typename OArray,typename O> class CustomShaderDescriptorInfo:public ShaderDescriptorInfo
|
||||
{
|
||||
IArray input;
|
||||
OArray output;
|
||||
|
||||
public:
|
||||
|
||||
CustomShaderDescriptorInfo():ShaderDescriptorInfo(SS){}
|
||||
virtual ~CustomShaderDescriptorInfo()override=default;
|
||||
|
||||
bool AddInput(I &item){return input.Add(item);}
|
||||
bool AddOutput(O &item){return output.Add(item);}
|
||||
|
||||
bool hasInput(const char *name)const{return input.IsMember(name);} ///<是否有指定输入
|
||||
|
||||
public:
|
||||
|
||||
IArray &GetInput(){return input;}
|
||||
OArray &GetOutput(){return output;}
|
||||
};//class CustomShaderDescriptorInfo
|
||||
|
||||
class VertexShaderDescriptorInfo:public CustomShaderDescriptorInfo<VK_SHADER_STAGE_VERTEX_BIT,VIAArray,VIA,SVArray,ShaderVariable >
|
||||
{
|
||||
SubpassInputDescriptorList subpass_input;
|
||||
|
||||
public:
|
||||
|
||||
const SubpassInputDescriptorList & GetSubpassInputList()const{return subpass_input;}
|
||||
|
||||
public:
|
||||
|
||||
using CustomShaderDescriptorInfo<VK_SHADER_STAGE_VERTEX_BIT,VIAArray,VIA,SVArray,ShaderVariable>::CustomShaderDescriptorInfo;
|
||||
~VertexShaderDescriptorInfo()override=default;
|
||||
|
||||
bool AddSubpassInput(const AnsiString name,uint8_t index);
|
||||
};//class VertexShaderDescriptorInfo
|
||||
|
||||
using TessCtrlShaderDescriptorInfo=CustomShaderDescriptorInfo<VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, SVArray, ShaderVariable, SVArray, ShaderVariable >;
|
||||
using TessEvalShaderDescriptorInfo=CustomShaderDescriptorInfo<VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, SVArray, ShaderVariable, SVArray, ShaderVariable >;
|
||||
using GeometryShaderDescriptorInfo=CustomShaderDescriptorInfo<VK_SHADER_STAGE_GEOMETRY_BIT, SVArray, ShaderVariable, SVArray, ShaderVariable >;
|
||||
using FragmentShaderDescriptorInfo=CustomShaderDescriptorInfo<VK_SHADER_STAGE_FRAGMENT_BIT, SVArray, ShaderVariable, VIAArray, VIA >;
|
||||
|
||||
}}//namespace hgl::graph
|
||||
|
Reference in New Issue
Block a user