VKRenderable and CommandBufferRender supported newly VertexInputLayout
This commit is contained in:
parent
6bdbf87446
commit
7031270476
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit d4d8af1bdcba53acc70fb6b2edf3b21a3a7245d9
|
||||
Subproject commit fbe4815c748346fae03d08bed7d228f45f02ac79
|
@ -1 +1 @@
|
||||
Subproject commit 405da4aa758983c99e3bf07b7de6a0d889731820
|
||||
Subproject commit 2d8ec257c213376d4c945da7eaf486fe5648e943
|
@ -48,9 +48,9 @@ private:
|
||||
AutoDelete<MaterialCreateInfo> mci;
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
mci=mtl::CreateVertexColor2D(CoordinateSystem2D::ZeroToOne);
|
||||
mci=mtl::CreateVertexColor2D(mtl::CoordinateSystem2D::ZeroToOne);
|
||||
#else
|
||||
mci=mtl::CreateVertexColor2D(CoordinateSystem2D::Ortho);
|
||||
mci=mtl::CreateVertexColor2D(mtl::CoordinateSystem2D::Ortho);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
//material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
|
||||
const UTF8String & GetName ()const{return data->name;}
|
||||
|
||||
const VertexInput * GetVertexInput ()const{return data->vertex_input;}
|
||||
// const VertexInput * GetVertexInput ()const{return data->vertex_input;}
|
||||
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
|
||||
|
||||
|
@ -7,22 +7,27 @@
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct VertexInputData
|
||||
{
|
||||
uint32_t count;
|
||||
|
||||
const char **name_list;
|
||||
const VkVertexInputBindingDescription *bind_list;
|
||||
const VkVertexInputAttributeDescription *attr_list;
|
||||
uint32_t first_binding;
|
||||
uint32_t binding_count;
|
||||
VkBuffer *buffer_list;
|
||||
VkDeviceSize *buffer_offset;
|
||||
};
|
||||
|
||||
struct VertexInputDataGroup
|
||||
{
|
||||
const VIL *vil;
|
||||
|
||||
VertexInputData vid[size_t(VertexInputGroup::RANGE_SIZE)];
|
||||
|
||||
public:
|
||||
|
||||
VertexInputData(const VIL *vil);
|
||||
~VertexInputData();
|
||||
VertexInputDataGroup(const VIL *);
|
||||
~VertexInputDataGroup();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -34,15 +39,13 @@ class Renderable
|
||||
MaterialInstance * mat_inst;
|
||||
Primitive * primitive;
|
||||
|
||||
VertexInputData * vertex_input_data;
|
||||
|
||||
uint32_t buffer_hash;
|
||||
VertexInputDataGroup *vid_group;
|
||||
|
||||
private:
|
||||
|
||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
|
||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputDataGroup *);
|
||||
|
||||
public:
|
||||
|
||||
@ -57,14 +60,17 @@ public:
|
||||
Primitive * GetPrimitive (){return primitive;}
|
||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||
|
||||
const VertexInputData * GetVertexInputData ()const{return vertex_input_data;}
|
||||
const VertexInputData * GetVertexInputData (const VertexInputGroup &vig)const
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(vig)
|
||||
|
||||
return vid_group->vid+size_t(vig);
|
||||
}
|
||||
|
||||
IndexBuffer * GetIndexBuffer ()const{return primitive->GetIndexBuffer();}
|
||||
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
|
||||
const uint32_t GetDrawCount ()const{return primitive->GetDrawCount();}
|
||||
|
||||
const uint32_t GetBufferHash ()const{return buffer_hash;}
|
||||
|
||||
MaterialParameters *GetMP (const DescriptorSetType &type){return mat_inst->GetMP(type);}
|
||||
|
||||
public: //instance support
|
||||
|
@ -37,9 +37,9 @@ namespace hgl
|
||||
}
|
||||
|
||||
const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型
|
||||
const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量
|
||||
// const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量
|
||||
const uint32_t GetCount ()const{return count;} ///<取得数据数量
|
||||
const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
||||
// const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
||||
void * GetData ()const{return mem_data;} ///<取得数据指针
|
||||
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
||||
};//class VertexAttribData
|
||||
|
@ -138,13 +138,23 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
||||
if(!ri)
|
||||
return(false);
|
||||
|
||||
const VertexInputData *vid=ri->GetVertexInputData();
|
||||
uint count=0;
|
||||
|
||||
if(vid->count<=0)
|
||||
ENUM_CLASS_FOR(VertexInputGroup,uint,i)
|
||||
{
|
||||
const VertexInputData *vid=ri->GetVertexInputData(VertexInputGroup(i));
|
||||
|
||||
if(vid->binding_count<=0)
|
||||
continue;
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,vid->first_binding,vid->binding_count,vid->buffer_list,vid->buffer_offset);
|
||||
|
||||
count+=vid->binding_count;
|
||||
}
|
||||
|
||||
if(count==0)
|
||||
return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vid->count,vid->buffer_list,vid->buffer_offset);
|
||||
|
||||
IndexBuffer *indices_buffer=ri->GetIndexBuffer();
|
||||
|
||||
if(indices_buffer)
|
||||
|
@ -3,48 +3,52 @@
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/util/hash/Hash.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using namespace util;
|
||||
|
||||
VertexInputData::VertexInputData(const VIL *vil)
|
||||
VertexInputDataGroup::VertexInputDataGroup(const VIL *vd)
|
||||
{
|
||||
count=vil->GetAttrCount();
|
||||
vil=vd;
|
||||
|
||||
name_list=vil->GetNameList();
|
||||
bind_list=vil->GetBindingList();
|
||||
attr_list=vil->GetAttributeList();
|
||||
uint first_binding=0;
|
||||
|
||||
buffer_list=new VkBuffer[count];
|
||||
buffer_offset=new VkDeviceSize[count];
|
||||
for(uint i=0;i<size_t(VertexInputGroup::RANGE_SIZE);i++)
|
||||
{
|
||||
vid[i].binding_count=vil->GetCount(VertexInputGroup(i));
|
||||
|
||||
if(vid[i].binding_count>0)
|
||||
{
|
||||
vid[i].first_binding=vil->GetFirstBinding(VertexInputGroup(i));
|
||||
|
||||
vid[i].buffer_list=new VkBuffer[vid[i].binding_count];
|
||||
vid[i].buffer_offset=new VkDeviceSize[vid[i].binding_count];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VertexInputData::~VertexInputData()
|
||||
VertexInputDataGroup::~VertexInputDataGroup()
|
||||
{
|
||||
delete[] buffer_list;
|
||||
delete[] buffer_offset;
|
||||
for(uint i=0;i<size_t(VertexInputGroup::RANGE_SIZE);i++)
|
||||
if(vid[i].binding_count>0)
|
||||
{
|
||||
delete[] vid[i].buffer_list;
|
||||
delete[] vid[i].buffer_offset;
|
||||
}
|
||||
}
|
||||
|
||||
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vid)
|
||||
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputDataGroup *vidg)
|
||||
{
|
||||
primitive=r;
|
||||
pipeline=p;
|
||||
mat_inst=mi;
|
||||
|
||||
vertex_input_data=vid;
|
||||
|
||||
if(vertex_input_data->count>0)
|
||||
CountHash<HASH::Adler32>(vertex_input_data->buffer_list,vertex_input_data->count*sizeof(VkBuffer),(void *)&buffer_hash);
|
||||
else
|
||||
buffer_hash=0;
|
||||
vid_group=vidg;
|
||||
}
|
||||
|
||||
Renderable::~Renderable()
|
||||
{
|
||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||
|
||||
delete vertex_input_data;
|
||||
delete vid_group;
|
||||
}
|
||||
|
||||
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
@ -52,7 +56,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
if(!prim||!mi||!p)return(nullptr);
|
||||
|
||||
const VIL *vil=mi->GetVIL();
|
||||
const int input_count=vil->GetAttrCount();
|
||||
const uint input_count=vil->GetCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的
|
||||
const UTF8String &mtl_name=mi->GetMaterial()->GetName();
|
||||
|
||||
if(prim->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||
@ -63,47 +67,47 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
}
|
||||
|
||||
VBO *vbo;
|
||||
const char *name;
|
||||
|
||||
VertexInputData *vid=new VertexInputData(vil);
|
||||
VertexInputDataGroup *vid_group=new VertexInputDataGroup(vil);
|
||||
|
||||
for(int i=0;i<input_count;i++)
|
||||
VertexInputData &vid=vid_group->vid[size_t(VertexInputGroup::Basic)];
|
||||
|
||||
const VertexInputFormat *vif=vil->GetFormatList(VertexInputGroup::Basic);
|
||||
|
||||
for(uint i=0;i<input_count;i++)
|
||||
{
|
||||
vbo=prim->GetVBO(vid->name_list[i],vid->buffer_offset+i);
|
||||
|
||||
name=vid->name_list[i];
|
||||
vbo=prim->GetVBO(vif->name,vid.buffer_offset+i);
|
||||
|
||||
if(!vbo)
|
||||
{
|
||||
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(vid->name_list[i])+"\" in Material: "+mtl_name);
|
||||
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vbo->GetFormat()!=vid->attr_list[i].format)
|
||||
if(vbo->GetFormat()!=vif->format)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(name)+
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(vif->name)+
|
||||
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") Format(")+GetVulkanFormatName(vid->attr_list[i].format)+
|
||||
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
|
||||
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
||||
")");
|
||||
delete vid;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vbo->GetStride()!=vid->bind_list[i].stride)
|
||||
if(vbo->GetStride()!=vif->stride)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(name)+
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(vif->name)+
|
||||
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") stride(")+UTF8String::numberOf(vid->bind_list[i].stride)+
|
||||
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
|
||||
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
||||
")");
|
||||
delete vid;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
vid->buffer_list[i]=vbo->GetBuffer();
|
||||
vid.buffer_list[i]=vbo->GetBuffer();
|
||||
++vif;
|
||||
}
|
||||
|
||||
return(new Renderable(prim,mi,p,vid));
|
||||
return(new Renderable(prim,mi,p,vid_group));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user