ULRE/inc/hgl/shadergen/ShaderDescriptorInfo.h

110 lines
4.1 KiB
C
Raw Normal View History

2024-06-18 02:04:11 +08:00
#pragma once
2023-03-03 23:02:40 +08:00
#include<hgl/type/Map.h>
2023-03-09 23:21:52 +08:00
#include<hgl/type/StringList.h>
2023-03-03 23:02:40 +08:00
#include<hgl/graph/VKShaderStage.h>
#include<hgl/graph/VKDescriptorSetType.h>
#include<hgl/graph/mtl/ShaderVariableType.h>
2023-03-17 10:14:07 +08:00
#include<hgl/shadergen/MaterialDescriptorInfo.h>
2023-03-03 23:02:40 +08:00
2023-03-21 18:05:48 +08:00
namespace hgl{namespace graph
{
2025-04-23 00:27:43 +08:00
using UBODescriptorList=ArrayList<const UBODescriptor *>;
using SamplerDescriptorList=ArrayList<const SamplerDescriptor *>;
2023-03-15 11:32:38 +08:00
using ConstValueDescriptorList=ObjectList<ConstValueDescriptor>;
using SubpassInputDescriptorList=ObjectList<SubpassInputDescriptor>;
2023-03-03 23:02:40 +08:00
/**
* Shader数据管理器,Shader前的资源统计
*/
2023-03-17 10:14:07 +08:00
class ShaderDescriptorInfo
2023-03-03 23:02:40 +08:00
{
protected:
2023-03-08 21:41:57 +08:00
VkShaderStageFlagBits stage_flag;
2023-03-14 22:22:35 +08:00
2023-03-09 23:21:52 +08:00
AnsiStringList struct_list; //用到的结构列表
2023-03-17 21:06:05 +08:00
//ubo/object在这里以及MaterialDescriptorInfo中均有一份mdi中的用于产生set/binding号这里的用于产生shader
2023-03-15 11:32:38 +08:00
UBODescriptorList ubo_list;
SamplerDescriptorList sampler_list;
2023-03-03 23:02:40 +08:00
2023-03-15 11:32:38 +08:00
ConstValueDescriptorList const_value_list;
2023-03-03 23:02:40 +08:00
ShaderPushConstant push_constant;
public:
2023-03-17 10:14:07 +08:00
ShaderDescriptorInfo(VkShaderStageFlagBits);
virtual ~ShaderDescriptorInfo()=default;
2023-03-03 23:02:40 +08:00
const VkShaderStageFlagBits GetShaderStage()const { return stage_flag; }
const AnsiString GetStageName()const { return AnsiString(GetShaderStageName(stage_flag)); }
2023-03-14 22:22:35 +08:00
2023-03-03 23:02:40 +08:00
public:
2023-03-15 11:32:38 +08:00
const AnsiStringList & GetStructList()const{return struct_list;}
2023-03-09 23:21:52 +08:00
2023-03-15 11:32:38 +08:00
const UBODescriptorList & GetUBOList()const{return ubo_list;}
const SamplerDescriptorList & GetSamplerList()const{return sampler_list;}
2023-03-03 23:02:40 +08:00
2023-03-15 11:32:38 +08:00
const ConstValueDescriptorList & GetConstList()const{return const_value_list;}
2023-03-03 23:02:40 +08:00
public:
2023-05-22 14:29:16 +08:00
void AddStruct(const AnsiString &);
bool AddUBO(DescriptorSetType type,const UBODescriptor *sd);
bool AddSampler(DescriptorSetType type,const SamplerDescriptor *sd);
2023-03-03 23:02:40 +08:00
bool AddConstValue(ConstValueDescriptor *sd);
2023-03-03 23:02:40 +08:00
2024-07-26 03:25:09 +08:00
void SetPushConstant(const AnsiString &name,uint8_t offset,uint8_t size);
2023-03-17 10:14:07 +08:00
};//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.Contains(name);} ///<是否有指定输入
public:
IArray &GetInput(){return input;}
OArray &GetOutput(){return output;}
2024-06-19 14:03:46 +08:00
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 >
{
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;
2024-07-26 03:25:09 +08:00
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 >;
2023-03-21 18:05:48 +08:00
}}//namespace hgl::graph