used newly ShaderAttributeArray
This commit is contained in:
parent
f748301787
commit
529d6b7939
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 41a2f9af7287765835d6b8b72a2a567be6eb17e0
|
Subproject commit 2f4a583b9c6eb71b752deb3f85674feb22b3cd08
|
@ -1 +1 @@
|
|||||||
Subproject commit d4999fb44535f0aa3d52295bad9a3f931d09f3a9
|
Subproject commit 17790c141d4a2a7e9c15a90216c3060469c40258
|
@ -6,7 +6,7 @@ using namespace hgl::shadergen;
|
|||||||
|
|
||||||
bool PureColor2DMaterial()
|
bool PureColor2DMaterial()
|
||||||
{
|
{
|
||||||
MaterialCreateInfo mc(1,false); //一个新材质,1个RT输出,默认使用Vertex/Fragment shader
|
MaterialCreateInfo mc("PureColor2D",1,false); //一个新材质,1个RT输出,默认使用Vertex/Fragment shader
|
||||||
|
|
||||||
//vertex部分
|
//vertex部分
|
||||||
{
|
{
|
||||||
@ -68,7 +68,7 @@ void main()
|
|||||||
|
|
||||||
bool VertexColor2DMaterial()
|
bool VertexColor2DMaterial()
|
||||||
{
|
{
|
||||||
MaterialCreateInfo mc(1,false);
|
MaterialCreateInfo mc("VertexColor2D",1,false);
|
||||||
|
|
||||||
//vertex部分
|
//vertex部分
|
||||||
{
|
{
|
||||||
|
@ -183,9 +183,9 @@ public: //Texture
|
|||||||
|
|
||||||
void Clear(TextureCreateInfo *);
|
void Clear(TextureCreateInfo *);
|
||||||
|
|
||||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const List<Image2DRegion> &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, uint32_t left,uint32_t top,uint32_t width,uint32_t height, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
bool ChangeTexture2D(Texture2D *,void *data, uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
bool ChangeTexture2D(Texture2D *,void *data, uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2<T> &rs)
|
bool ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const RectScope2<T> &rs)
|
||||||
@ -220,7 +220,7 @@ public: //shader & material
|
|||||||
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
|
PipelineLayoutData *CreatePipelineLayoutData(const MaterialDescriptorSets *);
|
||||||
void Destroy(PipelineLayoutData *);
|
void Destroy(PipelineLayoutData *);
|
||||||
|
|
||||||
DescriptorSet * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetType &type)const;
|
DescriptorSet * CreateDescriptorSets(const PipelineLayoutData *,const DescriptorSetType &type)const;
|
||||||
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetType &);
|
MaterialParameters *CreateMP(const MaterialDescriptorSets *,const PipelineLayoutData *,const DescriptorSetType &);
|
||||||
MaterialParameters *CreateMP(Material *,const DescriptorSetType &);
|
MaterialParameters *CreateMP(Material *,const DescriptorSetType &);
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include<hgl/graph/VKRenderable.h>
|
#include<hgl/graph/VKRenderable.h>
|
||||||
#include<hgl/graph/font/TextPrimitive.h>
|
#include<hgl/graph/font/TextPrimitive.h>
|
||||||
#include<hgl/type/ResManage.h>
|
#include<hgl/type/ResManage.h>
|
||||||
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using MaterialID =int;
|
using MaterialID =int;
|
||||||
using MaterialInstanceID =int;
|
using MaterialInstanceID =int;
|
||||||
@ -90,6 +91,8 @@ public: //Material
|
|||||||
const ShaderModule *CreateShaderModule(const OSString &filename,ShaderResource *shader_resource);
|
const ShaderModule *CreateShaderModule(const OSString &filename,ShaderResource *shader_resource);
|
||||||
|
|
||||||
Material * CreateMaterial(const OSString &);
|
Material * CreateMaterial(const OSString &);
|
||||||
|
Material * CreateMaterial(const hgl::shadergen::MaterialCreateInfo *);
|
||||||
|
|
||||||
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
||||||
MaterialInstance * CreateMaterialInstance(const OSString &,const VILConfig *vil_cfg=nullptr);
|
MaterialInstance * CreateMaterialInstance(const OSString &,const VILConfig *vil_cfg=nullptr);
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class VertexShaderModule:public ShaderModule
|
|||||||
uint32_t attr_count;
|
uint32_t attr_count;
|
||||||
VAT *type_list;
|
VAT *type_list;
|
||||||
const char **name_list;
|
const char **name_list;
|
||||||
ShaderAttribute **ssi_list;
|
ShaderAttribute *attr_list;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
const int GetInputBinding(const AnsiString &name)const{return shader_resource->GetInputBinding(name);}
|
const int GetInputBinding(const AnsiString &name)const{return shader_resource->GetInputBinding(name);}
|
||||||
const ShaderAttribute * GetInput (const AnsiString &name)const{return shader_resource->GetInput(name);}
|
const ShaderAttribute * GetInput (const AnsiString &name)const{return shader_resource->GetInput(name);}
|
||||||
const uint GetInputCount () const{return shader_resource->GetInputCount();}
|
const uint GetInputCount () const{return shader_resource->GetInputCount();}
|
||||||
const ShaderAttributeList & GetInputs () const{return shader_resource->GetInputs();}
|
const ShaderAttributeArray & GetInputs () const{return shader_resource->GetInputs();}
|
||||||
|
|
||||||
//const uint32_t GetAttrCount()const{return attr_count;}
|
//const uint32_t GetAttrCount()const{return attr_count;}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class ShaderResource
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ShaderResource(const VkShaderStageFlagBits &,const void *,const uint32);
|
ShaderResource(const VkShaderStageFlagBits &,const void *,const uint32);
|
||||||
virtual ~ShaderResource()=default;
|
virtual ~ShaderResource();
|
||||||
|
|
||||||
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
|
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
|
||||||
const char * GetStageName ()const {return GetShaderStageName(stage_flag);}
|
const char * GetStageName ()const {return GetShaderStageName(stage_flag);}
|
||||||
@ -29,11 +29,11 @@ public:
|
|||||||
const uint32_t * GetCode ()const {return (uint32_t *)spv_data;}
|
const uint32_t * GetCode ()const {return (uint32_t *)spv_data;}
|
||||||
const uint32_t GetCodeSize ()const {return spv_size;}
|
const uint32_t GetCodeSize ()const {return spv_size;}
|
||||||
|
|
||||||
ShaderAttributeList & GetInputs () {return stage_io.input;}
|
ShaderAttributeArray & GetInputs () {return stage_io.input;}
|
||||||
// ShaderAttributeList & GetOutputs () {return stage_io.output;}
|
// ShaderAttributeArray & GetOutputs () {return stage_io.output;}
|
||||||
|
|
||||||
const uint GetInputCount ()const {return stage_io.input.GetCount();}
|
const uint GetInputCount ()const {return stage_io.input.count;}
|
||||||
// const uint GetOutputCount ()const {return stage_io.output.GetCount();}
|
// const uint GetOutputCount ()const {return stage_io.output.count;}
|
||||||
|
|
||||||
const ShaderAttribute * GetInput (const AnsiString &)const;
|
const ShaderAttribute * GetInput (const AnsiString &)const;
|
||||||
const int GetInputBinding (const AnsiString &)const;
|
const int GetInputBinding (const AnsiString &)const;
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
SHADERGEN_NAMESPACE_BEGIN
|
SHADERGEN_NAMESPACE_BEGIN
|
||||||
class MaterialCreateInfo
|
class MaterialCreateInfo
|
||||||
{
|
{
|
||||||
|
AnsiString shader_name;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint rt_color_count; ///<输出的RT数量
|
uint rt_color_count; ///<输出的RT数量
|
||||||
@ -27,6 +29,10 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
const AnsiString &GetName()const{return shader_name;}
|
||||||
|
|
||||||
|
const uint32 GetShaderStage()const{return shader_stage;}
|
||||||
|
|
||||||
bool hasShader(const VkShaderStageFlagBits ss)const{return shader_stage&ss;}
|
bool hasShader(const VkShaderStageFlagBits ss)const{return shader_stage&ss;}
|
||||||
|
|
||||||
bool hasVertex ()const{return hasShader(VK_SHADER_STAGE_VERTEX_BIT);}
|
bool hasVertex ()const{return hasShader(VK_SHADER_STAGE_VERTEX_BIT);}
|
||||||
@ -42,7 +48,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MaterialCreateInfo(const uint rc,const bool rd,const uint32 ss=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT);
|
MaterialCreateInfo(const AnsiString &,const uint rc,const bool rd,const uint32 ss=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
~MaterialCreateInfo()=default;
|
~MaterialCreateInfo()=default;
|
||||||
|
|
||||||
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);
|
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);
|
||||||
|
@ -25,7 +25,7 @@ class ShaderDescriptorInfo
|
|||||||
|
|
||||||
AnsiStringList struct_list; //用到的结构列表
|
AnsiStringList struct_list; //用到的结构列表
|
||||||
|
|
||||||
//ubo/object在这里以及MaterialDescriptorInfo中均有一份,mdm中的用于产生set/binding号,这里的用于产生shader
|
//ubo/object在这里以及MaterialDescriptorInfo中均有一份,mdi中的用于产生set/binding号,这里的用于产生shader
|
||||||
UBODescriptorList ubo_list;
|
UBODescriptorList ubo_list;
|
||||||
SamplerDescriptorList sampler_list;
|
SamplerDescriptorList sampler_list;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/VKRenderResource.h>
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
#include<hgl/io/ConstBufferReader.h>
|
#include<hgl/io/ConstBufferReader.h>
|
||||||
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -185,5 +186,19 @@ Material *RenderResource::CreateMaterial(const OSString &filename)
|
|||||||
|
|
||||||
material_by_name.Add(filename,mtl);
|
material_by_name.Add(filename,mtl);
|
||||||
return(mtl);
|
return(mtl);
|
||||||
|
}
|
||||||
|
|
||||||
|
Material *RenderResource::CreateMaterial(const hgl::shadergen::MaterialCreateInfo *mci)
|
||||||
|
{
|
||||||
|
SHADERGEN_NAMESPACE_USING
|
||||||
|
|
||||||
|
if(!mci)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
const uint count=GetShaderCountByBits(mci->GetShaderStage());
|
||||||
|
ShaderModuleMap *smm=new ShaderModuleMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -44,18 +44,18 @@ ShaderModule::~ShaderModule()
|
|||||||
|
|
||||||
VertexShaderModule::VertexShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr):ShaderModule(dev,pssci,sr)
|
VertexShaderModule::VertexShaderModule(VkDevice dev,VkPipelineShaderStageCreateInfo *pssci,ShaderResource *sr):ShaderModule(dev,pssci,sr)
|
||||||
{
|
{
|
||||||
const ShaderAttributeList &stage_input_list=sr->GetInputs();
|
const ShaderAttributeArray &stage_input_list=sr->GetInputs();
|
||||||
|
|
||||||
attr_count=stage_input_list.GetCount();
|
attr_count=stage_input_list.count;
|
||||||
ssi_list=stage_input_list.GetData();
|
attr_list=stage_input_list.items;
|
||||||
name_list=new const char *[attr_count];
|
name_list=new const char *[attr_count];
|
||||||
type_list=new VAT[attr_count];
|
type_list=new VAT[attr_count];
|
||||||
|
|
||||||
for(uint i=0;i<attr_count;i++)
|
for(uint i=0;i<attr_count;i++)
|
||||||
{
|
{
|
||||||
name_list[i] =ssi_list[i]->name;
|
name_list[i] =attr_list[i].name;
|
||||||
type_list[i].basetype =VATBaseType(ssi_list[i]->basetype);
|
type_list[i].basetype =VATBaseType(attr_list[i].basetype);
|
||||||
type_list[i].vec_size =ssi_list[i]->vec_size;
|
type_list[i].vec_size =attr_list[i].vec_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +70,6 @@ VertexShaderModule::~VertexShaderModule()
|
|||||||
delete[] name_list;
|
delete[] name_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VkFormat GetVulkanFormat(const VATBaseType &base_type,const uint vec_size); //VertexAttrib.cpp
|
|
||||||
|
|
||||||
VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
||||||
{
|
{
|
||||||
VkVertexInputBindingDescription *binding_list=new VkVertexInputBindingDescription[attr_count];
|
VkVertexInputBindingDescription *binding_list=new VkVertexInputBindingDescription[attr_count];
|
||||||
@ -80,7 +78,7 @@ VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
|||||||
VkVertexInputBindingDescription *bind=binding_list;
|
VkVertexInputBindingDescription *bind=binding_list;
|
||||||
VkVertexInputAttributeDescription *attr=attribute_list;
|
VkVertexInputAttributeDescription *attr=attribute_list;
|
||||||
|
|
||||||
ShaderAttribute **si=ssi_list;
|
const ShaderAttribute *si=attr_list;
|
||||||
VAConfig vac;
|
VAConfig vac;
|
||||||
|
|
||||||
for(uint i=0;i<attr_count;i++)
|
for(uint i=0;i<attr_count;i++)
|
||||||
@ -91,16 +89,16 @@ VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
|||||||
//但在我们的设计中,仅支持一个流传递一个attrib
|
//但在我们的设计中,仅支持一个流传递一个attrib
|
||||||
|
|
||||||
attr->binding =i;
|
attr->binding =i;
|
||||||
attr->location =(*si)->location; //此值对应shader中的layout(location=
|
attr->location =si->location; //此值对应shader中的layout(location=
|
||||||
|
|
||||||
attr->offset =0;
|
attr->offset =0;
|
||||||
|
|
||||||
bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
||||||
//在Renderable类中,buffer_list必需严格按照本此binding为序列号排列
|
//在Renderable类中,buffer_list必需严格按照本此binding为序列号排列
|
||||||
|
|
||||||
if(!cfg||!cfg->Get((*si)->name,vac))
|
if(!cfg||!cfg->Get(si->name,vac))
|
||||||
{
|
{
|
||||||
attr->format =GetVulkanFormat(VATBaseType((*si)->basetype),(*si)->vec_size);
|
attr->format =GetVulkanFormat(si);
|
||||||
|
|
||||||
//if(memcmp((*si)->name.c_str(),"Inst_",5)==0) //不可以使用CaseComp("Inst_",5)会被认为是比较一个5字长的字符串,而不是只比较5个字符
|
//if(memcmp((*si)->name.c_str(),"Inst_",5)==0) //不可以使用CaseComp("Inst_",5)会被认为是比较一个5字长的字符串,而不是只比较5个字符
|
||||||
// bind->inputRate =VK_VERTEX_INPUT_RATE_INSTANCE;
|
// bind->inputRate =VK_VERTEX_INPUT_RATE_INSTANCE;
|
||||||
@ -112,7 +110,7 @@ VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
|||||||
if(vac.format!=PF_UNDEFINED)
|
if(vac.format!=PF_UNDEFINED)
|
||||||
attr->format =vac.format;
|
attr->format =vac.format;
|
||||||
else
|
else
|
||||||
attr->format =GetVulkanFormat(VATBaseType((*si)->basetype),(*si)->vec_size);
|
attr->format =GetVulkanFormat(si);
|
||||||
|
|
||||||
bind->inputRate =vac.instance?VK_VERTEX_INPUT_RATE_INSTANCE:VK_VERTEX_INPUT_RATE_VERTEX;
|
bind->inputRate =vac.instance?VK_VERTEX_INPUT_RATE_INSTANCE:VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ VK_NAMESPACE_BEGIN
|
|||||||
{
|
{
|
||||||
ObjectMap<OSString,ShaderResource> shader_resource_by_filename;
|
ObjectMap<OSString,ShaderResource> shader_resource_by_filename;
|
||||||
|
|
||||||
const bool LoadShaderStageAttributes(ShaderAttributeList &ss_list,io::ConstBufferReader &cbr)
|
const bool LoadShaderStageAttributes(ShaderAttributeArray &ss_list,io::ConstBufferReader &cbr)
|
||||||
{
|
{
|
||||||
uint count;
|
uint count;
|
||||||
|
|
||||||
@ -19,19 +19,19 @@ VK_NAMESPACE_BEGIN
|
|||||||
if(count<=0)
|
if(count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
ShaderAttribute *ss;
|
Init(ss_list,count);
|
||||||
|
|
||||||
|
ShaderAttribute *ss=ss_list.items;
|
||||||
|
|
||||||
for(uint i=0;i<count;i++)
|
for(uint i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
ss=new ShaderAttribute;
|
|
||||||
|
|
||||||
cbr.Read(ss->location);
|
cbr.Read(ss->location);
|
||||||
cbr.CastRead<uint8>(ss->basetype);
|
cbr.CastRead<uint8>(ss->basetype);
|
||||||
cbr.CastRead<uint8>(ss->vec_size);
|
cbr.CastRead<uint8>(ss->vec_size);
|
||||||
|
|
||||||
cbr.ReadTinyString(ss->name);
|
cbr.ReadTinyString(ss->name);
|
||||||
|
|
||||||
ss_list.Add(ss);
|
++ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -42,18 +42,26 @@ VK_NAMESPACE_BEGIN
|
|||||||
{
|
{
|
||||||
stage_flag=flag;
|
stage_flag=flag;
|
||||||
spv_data=sd;
|
spv_data=sd;
|
||||||
spv_size=size;
|
spv_size=size;
|
||||||
|
|
||||||
|
Init(stage_io);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderResource::~ShaderResource()
|
||||||
|
{
|
||||||
|
Clear(stage_io);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShaderAttribute *ShaderResource::GetInput(const AnsiString &name) const
|
const ShaderAttribute *ShaderResource::GetInput(const AnsiString &name) const
|
||||||
{
|
{
|
||||||
const int count=stage_io.input.GetCount();
|
if(stage_io.input.count<=0)return(nullptr);
|
||||||
ShaderAttribute **ss=stage_io.input.GetData();
|
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
const ShaderAttribute *ss=stage_io.input.items;
|
||||||
|
|
||||||
|
for(uint i=0;i<stage_io.input.count;i++)
|
||||||
{
|
{
|
||||||
if(name==(*ss)->name)
|
if(name==ss->name)
|
||||||
return *ss;
|
return ss;
|
||||||
|
|
||||||
++ss;
|
++ss;
|
||||||
}
|
}
|
||||||
@ -63,12 +71,13 @@ VK_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
const int ShaderResource::GetInputBinding(const AnsiString &name) const
|
const int ShaderResource::GetInputBinding(const AnsiString &name) const
|
||||||
{
|
{
|
||||||
const int count=stage_io.input.GetCount();
|
if(stage_io.input.count<=0)return(-1);
|
||||||
ShaderAttribute **ss=stage_io.input.GetData();
|
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
const ShaderAttribute *ss=stage_io.input.items;
|
||||||
|
|
||||||
|
for(uint i=0;i<stage_io.input.count;i++)
|
||||||
{
|
{
|
||||||
if(name==(*ss)->name)
|
if(name==ss->name)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
++ss;
|
++ss;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
|
#include<hgl/graph/VKShaderStage.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -17,6 +18,7 @@ namespace hgl
|
|||||||
namespace glsl_compiler
|
namespace glsl_compiler
|
||||||
{
|
{
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
|
using namespace hgl::graph;
|
||||||
|
|
||||||
enum class DescriptorType //等同VkDescriptorType
|
enum class DescriptorType //等同VkDescriptorType
|
||||||
{
|
{
|
||||||
@ -35,22 +37,6 @@ namespace glsl_compiler
|
|||||||
ENUM_CLASS_RANGE(SAMPLER,INPUT_ATTACHMENT)
|
ENUM_CLASS_RANGE(SAMPLER,INPUT_ATTACHMENT)
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr size_t SHADER_RESOURCE_NAME_MAX_LENGTH=32;
|
|
||||||
|
|
||||||
struct ShaderAttribute
|
|
||||||
{
|
|
||||||
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
|
||||||
uint8_t location;
|
|
||||||
uint8_t basetype; //现在改对应hgl/graph/VertexAttrib.h中的enum class VertexAttribType::BaseType
|
|
||||||
uint8_t vec_size;
|
|
||||||
};//
|
|
||||||
|
|
||||||
struct ShaderStageData
|
|
||||||
{
|
|
||||||
uint32_t count;
|
|
||||||
ShaderAttribute *items;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Descriptor
|
struct Descriptor
|
||||||
{
|
{
|
||||||
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
||||||
@ -90,8 +76,7 @@ namespace glsl_compiler
|
|||||||
uint32_t *spv_data;
|
uint32_t *spv_data;
|
||||||
uint32_t spv_length;
|
uint32_t spv_length;
|
||||||
|
|
||||||
ShaderStageData input,
|
ShaderStageIO stage_io;
|
||||||
output;
|
|
||||||
ShaderDescriptorResource resource;
|
ShaderDescriptorResource resource;
|
||||||
ShaderResourceData<PushConstant> push_constant;
|
ShaderResourceData<PushConstant> push_constant;
|
||||||
ShaderResourceData<SubpassInput> subpass_input;
|
ShaderResourceData<SubpassInput> subpass_input;
|
||||||
|
@ -5,8 +5,10 @@ using namespace hgl;
|
|||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
SHADERGEN_NAMESPACE_BEGIN
|
SHADERGEN_NAMESPACE_BEGIN
|
||||||
MaterialCreateInfo::MaterialCreateInfo(const uint rc,const bool rd,const uint32 ss)
|
MaterialCreateInfo::MaterialCreateInfo(const AnsiString &n,const uint rc,const bool rd,const uint32 ss)
|
||||||
{
|
{
|
||||||
|
shader_name=n;
|
||||||
|
|
||||||
rt_color_count=rc;
|
rt_color_count=rc;
|
||||||
rt_depth=rd;
|
rt_depth=rd;
|
||||||
|
|
||||||
|
@ -89,20 +89,24 @@ bool ShaderCreateInfo::ProcOutput()
|
|||||||
{
|
{
|
||||||
output_struct.Clear();
|
output_struct.Clear();
|
||||||
|
|
||||||
const ShaderAttributeList &ssl=sdm->GetShaderStageIO().output;
|
const ShaderAttributeArray &ssd=sdm->GetShaderStageIO().output;
|
||||||
|
|
||||||
if(ssl.GetCount()<=0)return(true);
|
if(ssd.count<=0)return(true);
|
||||||
|
|
||||||
output_struct=GetShaderStageName(shader_stage);
|
output_struct=GetShaderStageName(shader_stage);
|
||||||
output_struct+="_Output\n{\n";
|
output_struct+="_Output\n{\n";
|
||||||
|
|
||||||
for(auto *ss:ssl)
|
const ShaderAttribute *ss=ssd.items;
|
||||||
|
|
||||||
|
for(uint i=0;i<ssd.count;i++)
|
||||||
{
|
{
|
||||||
output_struct+="\t";
|
output_struct+="\t";
|
||||||
output_struct+=GetShaderAttributeTypename(ss);
|
output_struct+=GetShaderAttributeTypename(ss);
|
||||||
output_struct+=" ";
|
output_struct+=" ";
|
||||||
output_struct+=ss->name;
|
output_struct+=ss->name;
|
||||||
output_struct+=";\n";
|
output_struct+=";\n";
|
||||||
|
|
||||||
|
++ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
output_struct+="}";
|
output_struct+="}";
|
||||||
|
@ -11,15 +11,14 @@ void ShaderCreateInfoFragment::UseDefaultMain()
|
|||||||
|
|
||||||
const auto &output_list=sdm->GetShaderStageIO().output;
|
const auto &output_list=sdm->GetShaderStageIO().output;
|
||||||
|
|
||||||
const uint count=output_list.GetCount();
|
const ShaderAttribute *o=output_list.items;
|
||||||
ShaderAttribute **o=output_list.GetData();
|
|
||||||
|
|
||||||
for(uint i=0;i<count;i++)
|
for(uint i=0;i<output_list.count;i++)
|
||||||
{
|
{
|
||||||
main_codes+="\t";
|
main_codes+="\t";
|
||||||
main_codes+=(*o)->name;
|
main_codes+=o->name;
|
||||||
main_codes+="=Get";
|
main_codes+="=Get";
|
||||||
main_codes+=(*o)->name;
|
main_codes+=o->name;
|
||||||
main_codes+="();\n";
|
main_codes+="();\n";
|
||||||
|
|
||||||
++o;
|
++o;
|
||||||
@ -32,17 +31,16 @@ bool ShaderCreateInfoFragment::ProcOutput()
|
|||||||
{
|
{
|
||||||
const auto &output_list=sdm->GetShaderStageIO().output;
|
const auto &output_list=sdm->GetShaderStageIO().output;
|
||||||
|
|
||||||
const uint count=output_list.GetCount();
|
const ShaderAttribute *o=output_list.items;
|
||||||
ShaderAttribute **o=output_list.GetData();
|
|
||||||
|
|
||||||
for(uint i=0;i<count;i++)
|
for(uint i=0;i<output_list.count;i++)
|
||||||
{
|
{
|
||||||
final_shader+="layout(location=";
|
final_shader+="layout(location=";
|
||||||
final_shader+=AnsiString::numberOf(i);
|
final_shader+=AnsiString::numberOf(i);
|
||||||
final_shader+=") out ";
|
final_shader+=") out ";
|
||||||
final_shader+=GetShaderAttributeTypename(*o);
|
final_shader+=GetShaderAttributeTypename(o);
|
||||||
final_shader+=" ";
|
final_shader+=" ";
|
||||||
final_shader+=(*o)->name;
|
final_shader+=o->name;
|
||||||
final_shader+=";\n";
|
final_shader+=";\n";
|
||||||
|
|
||||||
++o;
|
++o;
|
||||||
|
@ -34,26 +34,27 @@ bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
|||||||
{
|
{
|
||||||
const auto &input=sdm->GetShaderStageIO().input;
|
const auto &input=sdm->GetShaderStageIO().input;
|
||||||
|
|
||||||
if(input.IsEmpty())
|
if(input.count<=0)
|
||||||
{
|
{
|
||||||
//no input ? this isn't a bug.
|
//no input ? this isn't a bug.
|
||||||
//maybe position info from UBO/SBBO/Texture.
|
//maybe position info from UBO/SBBO/Texture.
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!input.IsEmpty())
|
final_shader+="\n";
|
||||||
{
|
|
||||||
final_shader+="\n";
|
|
||||||
|
|
||||||
for(auto *ss:input)
|
const ShaderAttribute *ss=input.items;
|
||||||
{
|
|
||||||
final_shader+="layout(location=";
|
for(uint i=0;i<input.count;i++)
|
||||||
final_shader+=AnsiString::numberOf(ss->location);
|
{
|
||||||
final_shader+=") in ";
|
final_shader+="layout(location=";
|
||||||
final_shader+=GetShaderAttributeTypename(ss);
|
final_shader+=AnsiString::numberOf(ss->location);
|
||||||
final_shader+=" "+AnsiString(ss->name);
|
final_shader+=") in ";
|
||||||
final_shader+=";\n";
|
final_shader+=GetShaderAttributeTypename(ss);
|
||||||
}
|
final_shader+=" "+AnsiString(ss->name);
|
||||||
|
final_shader+=";\n";
|
||||||
|
|
||||||
|
++ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
@ -4,16 +4,21 @@ SHADERGEN_NAMESPACE_BEGIN
|
|||||||
ShaderDescriptorInfo::ShaderDescriptorInfo(VkShaderStageFlagBits flag_bit)
|
ShaderDescriptorInfo::ShaderDescriptorInfo(VkShaderStageFlagBits flag_bit)
|
||||||
{
|
{
|
||||||
stage_flag=flag_bit;
|
stage_flag=flag_bit;
|
||||||
|
|
||||||
|
Init(stage_io);
|
||||||
|
|
||||||
hgl_zero(push_constant);
|
hgl_zero(push_constant);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool Find(ObjectList<ShaderAttribute> &ol,const ShaderAttribute *ss)
|
bool Find(ShaderAttributeArray &sad,const ShaderAttribute *ss)
|
||||||
{
|
{
|
||||||
for(int i=0;i<ol.GetCount();i++)
|
if(sad.count<=0)
|
||||||
if(hgl::strcmp(ol[i]->name,ss->name)==0)
|
return(false);
|
||||||
|
|
||||||
|
for(uint i=0;i<sad.count;i++)
|
||||||
|
if(hgl::strcmp(sad.items[i].name,ss->name)==0)
|
||||||
return(true);
|
return(true);
|
||||||
|
|
||||||
return(false);
|
return(false);
|
||||||
@ -26,8 +31,9 @@ bool ShaderDescriptorInfo::AddInput(ShaderAttribute *ss)
|
|||||||
|
|
||||||
if(Find(stage_io.input,ss))return(false);
|
if(Find(stage_io.input,ss))return(false);
|
||||||
|
|
||||||
ss->location=stage_io.input.GetCount();
|
ss->location=stage_io.input.count;
|
||||||
stage_io.input.Add(ss);
|
|
||||||
|
Append(stage_io.input,ss);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,8 +43,9 @@ bool ShaderDescriptorInfo::AddOutput(ShaderAttribute *ss)
|
|||||||
|
|
||||||
if(Find(stage_io.output,ss))return(false);
|
if(Find(stage_io.output,ss))return(false);
|
||||||
|
|
||||||
ss->location=stage_io.output.GetCount();
|
ss->location=stage_io.output.count;
|
||||||
stage_io.output.Add(ss);
|
|
||||||
|
Append(stage_io.output,ss);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,20 +112,30 @@ void ShaderDescriptorInfo::DebugOutput(int index)
|
|||||||
|
|
||||||
LOG_INFO(UTF8String::numberOf(index)+": "+name+" shader");
|
LOG_INFO(UTF8String::numberOf(index)+": "+name+" shader");
|
||||||
|
|
||||||
if(stage_io.input.GetCount()>0)
|
if(stage_io.input.count>0)
|
||||||
{
|
{
|
||||||
LOG_INFO("\tStage Input "+UTF8String::numberOf(stage_io.input.GetCount()));
|
LOG_INFO("\tStage Input "+UTF8String::numberOf(stage_io.input.count));
|
||||||
|
|
||||||
for(auto *ss:stage_io.input)
|
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));
|
LOG_INFO("\t\tlayout(location="+UTF8String::numberOf(ss->location)+") in "+GetShaderAttributeTypename(ss)+"\t"+UTF8String(ss->name));
|
||||||
|
++ss;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stage_io.output.GetCount()>0)
|
if(stage_io.output.count>0)
|
||||||
{
|
{
|
||||||
LOG_INFO("\tStage Output "+UTF8String::numberOf(stage_io.output.GetCount()));
|
LOG_INFO("\tStage Output "+UTF8String::numberOf(stage_io.output.count));
|
||||||
|
|
||||||
for(auto *ss:stage_io.output)
|
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));
|
LOG_INFO("\t\tlayout(location="+UTF8String::numberOf(ss->location)+") out "+GetShaderAttributeTypename(ss)+"\t"+UTF8String(ss->name));
|
||||||
|
++ss;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ubo_list.GetCount()>0)
|
if(ubo_list.GetCount()>0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user