used newly ShaderAttributeArray
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/io/ConstBufferReader.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@@ -185,5 +186,19 @@ Material *RenderResource::CreateMaterial(const OSString &filename)
|
||||
|
||||
material_by_name.Add(filename,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
|
||||
|
@@ -44,18 +44,18 @@ ShaderModule::~ShaderModule()
|
||||
|
||||
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();
|
||||
ssi_list=stage_input_list.GetData();
|
||||
attr_count=stage_input_list.count;
|
||||
attr_list=stage_input_list.items;
|
||||
name_list=new const char *[attr_count];
|
||||
type_list=new VAT[attr_count];
|
||||
|
||||
for(uint i=0;i<attr_count;i++)
|
||||
{
|
||||
name_list[i] =ssi_list[i]->name;
|
||||
type_list[i].basetype =VATBaseType(ssi_list[i]->basetype);
|
||||
type_list[i].vec_size =ssi_list[i]->vec_size;
|
||||
name_list[i] =attr_list[i].name;
|
||||
type_list[i].basetype =VATBaseType(attr_list[i].basetype);
|
||||
type_list[i].vec_size =attr_list[i].vec_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +70,6 @@ VertexShaderModule::~VertexShaderModule()
|
||||
delete[] name_list;
|
||||
}
|
||||
|
||||
const VkFormat GetVulkanFormat(const VATBaseType &base_type,const uint vec_size); //VertexAttrib.cpp
|
||||
|
||||
VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
||||
{
|
||||
VkVertexInputBindingDescription *binding_list=new VkVertexInputBindingDescription[attr_count];
|
||||
@@ -80,7 +78,7 @@ VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
||||
VkVertexInputBindingDescription *bind=binding_list;
|
||||
VkVertexInputAttributeDescription *attr=attribute_list;
|
||||
|
||||
ShaderAttribute **si=ssi_list;
|
||||
const ShaderAttribute *si=attr_list;
|
||||
VAConfig vac;
|
||||
|
||||
for(uint i=0;i<attr_count;i++)
|
||||
@@ -91,16 +89,16 @@ VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
||||
//但在我们的设计中,仅支持一个流传递一个attrib
|
||||
|
||||
attr->binding =i;
|
||||
attr->location =(*si)->location; //此值对应shader中的layout(location=
|
||||
attr->location =si->location; //此值对应shader中的layout(location=
|
||||
|
||||
attr->offset =0;
|
||||
|
||||
bind->binding =i; //binding对应在vkCmdBindVertexBuffer中设置的缓冲区的序列号,所以这个数字必须从0开始,而且紧密排列。
|
||||
//在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个字符
|
||||
// bind->inputRate =VK_VERTEX_INPUT_RATE_INSTANCE;
|
||||
@@ -112,7 +110,7 @@ VIL *VertexShaderModule::CreateVIL(const VILConfig *cfg)
|
||||
if(vac.format!=PF_UNDEFINED)
|
||||
attr->format =vac.format;
|
||||
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;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ VK_NAMESPACE_BEGIN
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -19,19 +19,19 @@ VK_NAMESPACE_BEGIN
|
||||
if(count<=0)
|
||||
return(false);
|
||||
|
||||
ShaderAttribute *ss;
|
||||
Init(ss_list,count);
|
||||
|
||||
ShaderAttribute *ss=ss_list.items;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
ss=new ShaderAttribute;
|
||||
|
||||
cbr.Read(ss->location);
|
||||
cbr.CastRead<uint8>(ss->basetype);
|
||||
cbr.CastRead<uint8>(ss->vec_size);
|
||||
|
||||
cbr.ReadTinyString(ss->name);
|
||||
|
||||
ss_list.Add(ss);
|
||||
++ss;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -42,18 +42,26 @@ VK_NAMESPACE_BEGIN
|
||||
{
|
||||
stage_flag=flag;
|
||||
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 int count=stage_io.input.GetCount();
|
||||
ShaderAttribute **ss=stage_io.input.GetData();
|
||||
if(stage_io.input.count<=0)return(nullptr);
|
||||
|
||||
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)
|
||||
return *ss;
|
||||
if(name==ss->name)
|
||||
return ss;
|
||||
|
||||
++ss;
|
||||
}
|
||||
@@ -63,12 +71,13 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
const int ShaderResource::GetInputBinding(const AnsiString &name) const
|
||||
{
|
||||
const int count=stage_io.input.GetCount();
|
||||
ShaderAttribute **ss=stage_io.input.GetData();
|
||||
if(stage_io.input.count<=0)return(-1);
|
||||
|
||||
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;
|
||||
|
||||
++ss;
|
||||
|
Reference in New Issue
Block a user