ULRE/inc/hgl/shadergen/MaterialDescriptorInfo.h

73 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include<hgl/graph/VKShaderDescriptorSet.h>
#include<hgl/graph/mtl/ShaderBufferSource.h>
#include<hgl/type/Map.h>
namespace hgl{namespace graph{
/**
* 材质描述符管理</p>
* 该类使用于SHADER生成前用于统计编号set/binding
*/
class MaterialDescriptorInfo
{
uint descriptor_count;
ShaderDescriptorSetArray desc_set_array;
Map<AnsiString,AnsiString> struct_map;
Map<AnsiString,UBODescriptor *> ubo_map;
Map<AnsiString,SamplerDescriptor *> sampler_map;
public:
MaterialDescriptorInfo();
~MaterialDescriptorInfo()=default;
bool AddStruct(const AnsiString &name,const AnsiString &code)
{
struct_map.Add(name,code);
return(true);
}
bool AddStruct(const ShaderBufferSource &ss)
{
return(AddStruct(ss.struct_name,ss.codes));
}
bool GetStruct(const AnsiString &name,AnsiString &code)
{
return(struct_map.Get(name,code));
}
bool hasStruct(const AnsiString &name) const
{
return(struct_map.ContainsKey(name));
}
const UBODescriptor *AddUBO(uint32_t shader_stage_flag_bits,DescriptorSetType set_type,UBODescriptor *sd);
const SamplerDescriptor *AddSampler(uint32_t shader_stage_flag_bits,DescriptorSetType set_type,SamplerDescriptor *sd);
UBODescriptor *GetUBO(const AnsiString &name);
SamplerDescriptor *GetSampler(const AnsiString &name);
const DescriptorSetType GetSetType(const AnsiString &)const;
void Resort(); //排序产生set号与binding号
const uint GetCount()const
{
return descriptor_count;
}
const ShaderDescriptorSetArray &Get()const
{
return desc_set_array;
}
const bool hasSet(const DescriptorSetType &type)const
{
return desc_set_array[size_t(type)].count>0;
}
};//class MaterialDescriptorInfo
}}//namespace hgl::graph