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
|
@ -37,9 +37,9 @@ private:
|
|||||||
|
|
||||||
MaterialInstance * material_instance =nullptr;
|
MaterialInstance * material_instance =nullptr;
|
||||||
Renderable * render_obj =nullptr;
|
Renderable * render_obj =nullptr;
|
||||||
DeviceBuffer * ubo_camera_info =nullptr;
|
DeviceBuffer * ubo_camera_info =nullptr;
|
||||||
DeviceBuffer * ubo_color_material =nullptr;
|
DeviceBuffer * ubo_color_material =nullptr;
|
||||||
DeviceBuffer * ubo_line_config =nullptr;
|
DeviceBuffer * ubo_line_config =nullptr;
|
||||||
|
|
||||||
Pipeline * pipeline =nullptr;
|
Pipeline * pipeline =nullptr;
|
||||||
|
|
||||||
|
@ -48,9 +48,9 @@ private:
|
|||||||
AutoDelete<MaterialCreateInfo> mci;
|
AutoDelete<MaterialCreateInfo> mci;
|
||||||
|
|
||||||
#ifdef USE_ZERO2ONE_COORD
|
#ifdef USE_ZERO2ONE_COORD
|
||||||
mci=mtl::CreateVertexColor2D(CoordinateSystem2D::ZeroToOne);
|
mci=mtl::CreateVertexColor2D(mtl::CoordinateSystem2D::ZeroToOne);
|
||||||
#else
|
#else
|
||||||
mci=mtl::CreateVertexColor2D(CoordinateSystem2D::Ortho);
|
mci=mtl::CreateVertexColor2D(mtl::CoordinateSystem2D::Ortho);
|
||||||
#endif//USE_ZERO2ONE_COORD
|
#endif//USE_ZERO2ONE_COORD
|
||||||
|
|
||||||
//material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
//material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
const UTF8String & GetName ()const{return data->name;}
|
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;}
|
const ShaderStageCreateInfoList & GetStageList ()const{return data->shader_stage_list;}
|
||||||
|
|
||||||
|
@ -7,22 +7,27 @@
|
|||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKMaterialParameters.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
|
#include<hgl/graph/VertexAttrib.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
struct VertexInputData
|
struct VertexInputData
|
||||||
{
|
{
|
||||||
uint32_t count;
|
uint32_t first_binding;
|
||||||
|
uint32_t binding_count;
|
||||||
const char **name_list;
|
|
||||||
const VkVertexInputBindingDescription *bind_list;
|
|
||||||
const VkVertexInputAttributeDescription *attr_list;
|
|
||||||
VkBuffer *buffer_list;
|
VkBuffer *buffer_list;
|
||||||
VkDeviceSize *buffer_offset;
|
VkDeviceSize *buffer_offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexInputDataGroup
|
||||||
|
{
|
||||||
|
const VIL *vil;
|
||||||
|
|
||||||
|
VertexInputData vid[size_t(VertexInputGroup::RANGE_SIZE)];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VertexInputData(const VIL *vil);
|
VertexInputDataGroup(const VIL *);
|
||||||
~VertexInputData();
|
~VertexInputDataGroup();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,15 +39,13 @@ class Renderable
|
|||||||
MaterialInstance * mat_inst;
|
MaterialInstance * mat_inst;
|
||||||
Primitive * primitive;
|
Primitive * primitive;
|
||||||
|
|
||||||
VertexInputData * vertex_input_data;
|
VertexInputDataGroup *vid_group;
|
||||||
|
|
||||||
uint32_t buffer_hash;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||||
|
|
||||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
|
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputDataGroup *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -57,14 +60,17 @@ public:
|
|||||||
Primitive * GetPrimitive (){return primitive;}
|
Primitive * GetPrimitive (){return primitive;}
|
||||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
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();}
|
IndexBuffer * GetIndexBuffer ()const{return primitive->GetIndexBuffer();}
|
||||||
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
|
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
|
||||||
const uint32_t GetDrawCount ()const{return primitive->GetDrawCount();}
|
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);}
|
MaterialParameters *GetMP (const DescriptorSetType &type){return mat_inst->GetMP(type);}
|
||||||
|
|
||||||
public: //instance support
|
public: //instance support
|
||||||
|
@ -37,9 +37,9 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型
|
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 GetCount ()const{return count;} ///<取得数据数量
|
||||||
const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
// const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
||||||
void * GetData ()const{return mem_data;} ///<取得数据指针
|
void * GetData ()const{return mem_data;} ///<取得数据指针
|
||||||
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
||||||
};//class VertexAttribData
|
};//class VertexAttribData
|
||||||
|
@ -138,13 +138,23 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
|||||||
if(!ri)
|
if(!ri)
|
||||||
return(false);
|
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);
|
return(false);
|
||||||
|
|
||||||
vkCmdBindVertexBuffers(cmd_buf,0,vid->count,vid->buffer_list,vid->buffer_offset);
|
|
||||||
|
|
||||||
IndexBuffer *indices_buffer=ri->GetIndexBuffer();
|
IndexBuffer *indices_buffer=ri->GetIndexBuffer();
|
||||||
|
|
||||||
if(indices_buffer)
|
if(indices_buffer)
|
||||||
|
@ -3,48 +3,52 @@
|
|||||||
#include<hgl/graph/VKMaterialParameters.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKMaterial.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||||
#include<hgl/util/hash/Hash.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using namespace util;
|
VertexInputDataGroup::VertexInputDataGroup(const VIL *vd)
|
||||||
|
|
||||||
VertexInputData::VertexInputData(const VIL *vil)
|
|
||||||
{
|
{
|
||||||
count=vil->GetAttrCount();
|
vil=vd;
|
||||||
|
|
||||||
name_list=vil->GetNameList();
|
uint first_binding=0;
|
||||||
bind_list=vil->GetBindingList();
|
|
||||||
attr_list=vil->GetAttributeList();
|
|
||||||
|
|
||||||
buffer_list=new VkBuffer[count];
|
for(uint i=0;i<size_t(VertexInputGroup::RANGE_SIZE);i++)
|
||||||
buffer_offset=new VkDeviceSize[count];
|
{
|
||||||
|
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;
|
for(uint i=0;i<size_t(VertexInputGroup::RANGE_SIZE);i++)
|
||||||
delete[] buffer_offset;
|
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;
|
primitive=r;
|
||||||
pipeline=p;
|
pipeline=p;
|
||||||
mat_inst=mi;
|
mat_inst=mi;
|
||||||
|
|
||||||
vertex_input_data=vid;
|
vid_group=vidg;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable::~Renderable()
|
Renderable::~Renderable()
|
||||||
{
|
{
|
||||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||||
|
|
||||||
delete vertex_input_data;
|
delete vid_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
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);
|
if(!prim||!mi||!p)return(nullptr);
|
||||||
|
|
||||||
const VIL *vil=mi->GetVIL();
|
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();
|
const UTF8String &mtl_name=mi->GetMaterial()->GetName();
|
||||||
|
|
||||||
if(prim->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
if(prim->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||||
@ -63,47 +67,47 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
VBO *vbo;
|
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);
|
vbo=prim->GetVBO(vif->name,vid.buffer_offset+i);
|
||||||
|
|
||||||
name=vid->name_list[i];
|
|
||||||
|
|
||||||
if(!vbo)
|
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);
|
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 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())+
|
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
||||||
")");
|
")");
|
||||||
delete vid;
|
|
||||||
return(nullptr);
|
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 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())+
|
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
||||||
")");
|
")");
|
||||||
delete vid;
|
|
||||||
return(nullptr);
|
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
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user