[WIP] optimizing VDM Support
This commit is contained in:
@@ -130,11 +130,17 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::BindIBO(IndexBuffer *ibo,VkDeviceSize offset)
|
||||
void RenderCmdBuffer::BindIBO(IBAccess *iba)
|
||||
{
|
||||
if(!iba)return;
|
||||
|
||||
IndexBuffer *ibo=iba->buffer;
|
||||
|
||||
if(!ibo)return;
|
||||
|
||||
vkCmdBindIndexBuffer(cmd_buf,
|
||||
ibo->GetBuffer(),
|
||||
offset*ibo->GetStride(),
|
||||
iba->start*ibo->GetStride(),
|
||||
VkIndexType(ibo->GetType()));
|
||||
}
|
||||
|
||||
@@ -143,7 +149,7 @@ bool RenderCmdBuffer::BindVAB(Renderable *ri)
|
||||
if(!ri)
|
||||
return(false);
|
||||
|
||||
const PrimitiveRenderBuffer *prb=ri->GetRenderBuffer();
|
||||
const PrimitiveDataBuffer *prb=ri->GetRenderBuffer();
|
||||
|
||||
if(prb->vab_count<=0)
|
||||
return(false);
|
||||
@@ -153,10 +159,10 @@ bool RenderCmdBuffer::BindVAB(Renderable *ri)
|
||||
if(prd->vertex_count<=0)
|
||||
return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,prb->vab_count,prb->vab_list,prd->vab_offset);
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,prb->vab_count,prb->vab_list,prb->vab_offset);
|
||||
|
||||
if(prb->ibo&&prd->index_count)
|
||||
BindIBO(prb->ibo,prd->index_start);
|
||||
if(prb->ib_access->buffer)
|
||||
BindIBO(prb->ib_access);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -185,12 +191,12 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer,
|
||||
vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride);
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::Draw(const PrimitiveRenderBuffer *prb,const PrimitiveRenderData *prd)
|
||||
void RenderCmdBuffer::Draw(const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd)
|
||||
{
|
||||
if(!prb||!prd)
|
||||
return;
|
||||
|
||||
if (prb->ibo)
|
||||
if (prb->ib_access->buffer)
|
||||
DrawIndexed(prd->index_count);
|
||||
else
|
||||
Draw(prd->vertex_count);
|
||||
|
@@ -13,7 +13,7 @@ Material::Material(const AnsiString &n)
|
||||
{
|
||||
name=n;
|
||||
|
||||
primitive_render_buffer=nullptr;
|
||||
vertex_input=nullptr;
|
||||
shader_maps=new ShaderModuleMap;
|
||||
desc_manager=nullptr;
|
||||
pipeline_layout_data=nullptr;
|
||||
@@ -28,7 +28,7 @@ Material::~Material()
|
||||
{
|
||||
SAFE_CLEAR(mi_data_manager);
|
||||
|
||||
ReleaseVertexInput(primitive_render_buffer);
|
||||
ReleaseVertexInput(vertex_input);
|
||||
delete shader_maps; //不用SAFE_CLEAR是因为这个一定会有
|
||||
SAFE_CLEAR(desc_manager);
|
||||
SAFE_CLEAR(pipeline_layout_data);
|
||||
@@ -49,22 +49,22 @@ const bool Material::hasSet(const DescriptorSetType &dst)const
|
||||
|
||||
const VIL *Material::GetDefaultVIL()const
|
||||
{
|
||||
return primitive_render_buffer->GetDefaultVIL();
|
||||
return vertex_input->GetDefaultVIL();
|
||||
}
|
||||
|
||||
VIL *Material::CreateVIL(const VILConfig *format_map)
|
||||
{
|
||||
return primitive_render_buffer->CreateVIL(format_map);
|
||||
return vertex_input->CreateVIL(format_map);
|
||||
}
|
||||
|
||||
bool Material::Release(VIL *vil)
|
||||
{
|
||||
return primitive_render_buffer->Release(vil);
|
||||
return vertex_input->Release(vil);
|
||||
}
|
||||
|
||||
const uint Material::GetVILCount()
|
||||
{
|
||||
return primitive_render_buffer->GetInstanceCount();
|
||||
return vertex_input->GetInstanceCount();
|
||||
}
|
||||
|
||||
bool Material::BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
||||
|
@@ -13,14 +13,14 @@ PrimitiveData::PrimitiveData(const VIL *_vil,const uint32_t vc)
|
||||
|
||||
vertex_count=vc;
|
||||
|
||||
vab_access=hgl_zero_new<VABAccess>(_vil->GetCount());
|
||||
vab_list=hgl_zero_new<VAB *>(_vil->GetCount());
|
||||
|
||||
hgl_zero(ib_access);
|
||||
ibo=nullptr;
|
||||
}
|
||||
|
||||
PrimitiveData::~PrimitiveData()
|
||||
{
|
||||
SAFE_CLEAR_ARRAY(vab_access); //注意:这里并不释放VAB,在派生类中释放
|
||||
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
||||
}
|
||||
|
||||
const int PrimitiveData::GetVABCount()const
|
||||
@@ -35,58 +35,13 @@ const int PrimitiveData::GetVABIndex(const AnsiString &name) const
|
||||
return vil->GetIndex(name);
|
||||
}
|
||||
|
||||
VABAccess *PrimitiveData::GetVABAccess(const int index)
|
||||
VAB *PrimitiveData::GetVAB(const int index)
|
||||
{
|
||||
if(index<0||index>=vil->GetCount())return(nullptr);
|
||||
|
||||
return vab_access+index;
|
||||
return vab_list[index];
|
||||
}
|
||||
|
||||
VABAccess *PrimitiveData::GetVABAccess(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0)return(nullptr);
|
||||
|
||||
return vab_access+index;
|
||||
}
|
||||
|
||||
//VABAccess *SetVAB(PrimitiveData *pd,const int index,VAB *vab,VkDeviceSize start,VkDeviceSize count)
|
||||
//{
|
||||
// if(!pd)return(nullptr);
|
||||
// if(!pd->vil)return(nullptr);
|
||||
// if(index<0||index>=pd->vil->GetCount())return(nullptr);
|
||||
//
|
||||
// VABAccess *vaba=pd->vab_access+index;
|
||||
//
|
||||
// vaba->vab=vab;
|
||||
// vaba->start=start;
|
||||
// vaba->count=count;
|
||||
//
|
||||
// //#ifdef _DEBUG
|
||||
// // DebugUtils *du=device->GetDebugUtils();
|
||||
//
|
||||
// // if(du)
|
||||
// // {
|
||||
// // du->SetBuffer(vab->GetBuffer(),prim_name+":VAB:Buffer:"+name);
|
||||
// // du->SetDeviceMemory(vab->GetVkMemory(),prim_name+":VAB:Memory:"+name);
|
||||
// // }
|
||||
// //#endif//_DEBUG
|
||||
//
|
||||
// return vaba;
|
||||
//}
|
||||
|
||||
//void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
||||
//{
|
||||
// if(!pd)return;
|
||||
//
|
||||
// pd->ib_access.buffer=ib;
|
||||
// pd->ib_access.start=0;
|
||||
// pd->ib_access.count=ic;
|
||||
//}
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
@@ -98,7 +53,10 @@ namespace
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager *GetVDM(){return nullptr;}
|
||||
int32_t GetVertexOffset ()const override{return 0;}
|
||||
uint32_t GetFirstIndex ()const override{return 0;}
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveDataPrivateBuffer(GPUDevice *dev,const VIL *_vil,const uint32_t vc):PrimitiveData(_vil,vc)
|
||||
{
|
||||
@@ -107,83 +65,65 @@ namespace
|
||||
|
||||
~PrimitiveDataPrivateBuffer() override
|
||||
{
|
||||
VABAccess *vab=vab_access;
|
||||
VAB **vab=vab_list;
|
||||
|
||||
for(uint i=0;i<vil->GetCount();i++)
|
||||
{
|
||||
if(vab->vab)
|
||||
{
|
||||
delete vab->vab;
|
||||
vab->vab=nullptr;
|
||||
}
|
||||
if(*vab)
|
||||
delete *vab;
|
||||
|
||||
++vab;
|
||||
}
|
||||
|
||||
if(ib_access.buffer)
|
||||
{
|
||||
delete ib_access.buffer;
|
||||
ib_access.buffer=nullptr;
|
||||
}
|
||||
if(ibo)
|
||||
delete ibo;
|
||||
}
|
||||
|
||||
IBAccess *InitIBO(const uint32_t index_count,IndexType it) override
|
||||
IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
|
||||
if(ib_access.buffer)
|
||||
{
|
||||
delete ib_access.buffer;
|
||||
ib_access.buffer=nullptr;
|
||||
}
|
||||
if(ibo)delete ibo;
|
||||
|
||||
ib_access.buffer=device->CreateIBO(it,index_count);
|
||||
ibo=device->CreateIBO(it,ic);
|
||||
|
||||
if(!ib_access.buffer)
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
|
||||
ib_access.start=0;
|
||||
ib_access.count=index_count;
|
||||
index_count=ic;
|
||||
|
||||
return(&ib_access);
|
||||
return(ibo);
|
||||
}
|
||||
|
||||
VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data)
|
||||
VAB *InitVAB(const int vab_index,const VkFormat &format,const void *data)
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0||index>=vil->GetCount())
|
||||
if(vab_index<0||vab_index>=vil->GetCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
VABAccess *vaba=vab_access+index;
|
||||
|
||||
if(!vaba->vab)
|
||||
if(!vab_list[vab_index])
|
||||
{
|
||||
vaba->vab=device->CreateVAB(format,vertex_count,data);
|
||||
vab_list[vab_index]=device->CreateVAB(format,vertex_count,data);
|
||||
|
||||
if(!vaba->vab)
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
|
||||
vaba->start=0;
|
||||
vaba->count=vertex_count;
|
||||
}
|
||||
else
|
||||
|
||||
if(vab_list[vab_index]&&data)
|
||||
{
|
||||
vaba->vab->Write(data,vertex_count);
|
||||
vab_list[vab_index]->Write(data,vertex_count);
|
||||
}
|
||||
|
||||
return vaba;
|
||||
return vab_list[vab_index];
|
||||
}
|
||||
};//class PrimitiveDataPrivateBuffer:public PrimitiveData
|
||||
|
||||
@@ -199,7 +139,8 @@ namespace
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager *GetVDM(){return vdm;}
|
||||
int32_t GetVertexOffset()const override { return vab_node->GetStart(); }
|
||||
uint32_t GetFirstIndex ()const override { return ib_node->GetStart(); }
|
||||
|
||||
PrimitiveDataVDM(VertexDataManager *_vdm,const uint32_t vc):PrimitiveData(_vdm->GetVIL(),vc)
|
||||
{
|
||||
@@ -218,7 +159,7 @@ namespace
|
||||
vdm->ReleaseVAB(vab_node);
|
||||
}
|
||||
|
||||
IBAccess *InitIBO(const uint32_t index_count,IndexType it) override
|
||||
IndexBuffer *InitIBO(const uint32_t index_count,IndexType it) override
|
||||
{
|
||||
if(index_count<=0)return(nullptr);
|
||||
if(!vdm)return(nullptr);
|
||||
@@ -230,49 +171,39 @@ namespace
|
||||
if(!ib_node)
|
||||
return(nullptr);
|
||||
|
||||
ib_access.buffer=vdm->GetIBO();
|
||||
ib_access.start =ib_node->GetStart();
|
||||
ib_access.count =ib_node->GetCount();
|
||||
ibo=vdm->GetIBO();
|
||||
}
|
||||
|
||||
return &ib_access;
|
||||
return ibo;
|
||||
}
|
||||
|
||||
VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data)
|
||||
VAB *InitVAB(const int vab_index,const VkFormat &format,const void *data)
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0||index>=vil->GetCount())
|
||||
if (vab_index<0||vab_index>=vil->GetCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
VABAccess *vaba=vab_access+index;
|
||||
|
||||
if(!vaba->vab)
|
||||
if (!vab_list[vab_index])
|
||||
{
|
||||
vaba->vab=vdm->GetVAB(index);
|
||||
vab_list[vab_index]=vdm->GetVAB(vab_index);
|
||||
|
||||
if(!vaba->vab)
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
|
||||
vaba->start=vab_node->GetStart();
|
||||
vaba->count=vab_node->GetCount();
|
||||
}
|
||||
|
||||
if(vaba->vab&&data)
|
||||
vaba->vab->Write(data,vaba->start,vaba->count);
|
||||
if(vab_list[vab_index]&&data)
|
||||
vab_list[vab_index]->Write(data,vab_node->GetStart(),vertex_count);
|
||||
|
||||
return vaba;
|
||||
return vab_list[vab_index];
|
||||
}
|
||||
};//class PrimitiveDataVDM:public PrimitiveData
|
||||
}//namespace
|
||||
|
@@ -19,12 +19,13 @@ class PrimitiveData
|
||||
{
|
||||
protected:
|
||||
|
||||
const VIL * vil;
|
||||
const VIL * vil;
|
||||
|
||||
uint32_t vertex_count;
|
||||
uint32_t vertex_count;
|
||||
uint32_t index_count;
|
||||
|
||||
VABAccess * vab_access;
|
||||
IBAccess ib_access;
|
||||
VAB ** vab_list;
|
||||
IndexBuffer * ibo;
|
||||
|
||||
public:
|
||||
|
||||
@@ -36,22 +37,20 @@ public:
|
||||
const uint32_t GetVertexCount ()const{return vertex_count;}
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VABAccess * GetVABAccess (const int index);
|
||||
VABAccess * GetVABAccess (const AnsiString &name);
|
||||
VAB * GetVAB (const int index);
|
||||
|
||||
IBAccess * GetIBAccess (){return &ib_access;}
|
||||
IndexBuffer * GetIBO (){return ib_access.buffer;}
|
||||
IndexBuffer * GetIBO (){return ibo;}
|
||||
uint32_t GetIndexCount ()const{return index_count;}
|
||||
|
||||
virtual int32_t GetVertexOffset ()const=0; ///<取得顶点偏移(注意是顶点不是字节)
|
||||
virtual uint32_t GetFirstIndex ()const=0; ///<取得第一个索引
|
||||
|
||||
public:
|
||||
|
||||
virtual VertexDataManager *GetVDM()=0;
|
||||
|
||||
public:
|
||||
|
||||
virtual IBAccess * InitIBO(const uint32_t index_count,IndexType it)=0;
|
||||
virtual VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data)=0;
|
||||
virtual IndexBuffer * InitIBO(const uint32_t index_count,IndexType it)=0;
|
||||
virtual VAB * InitVAB(const int vab_index,const VkFormat &format,const void *data)=0;
|
||||
};//class PrimitiveData
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const uint32_t vc);
|
||||
PrimitiveData *CreatePrimitiveData(VertexDataManager *vdm,const uint32_t vc);
|
||||
VK_NAMESPACE_END
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -124,7 +124,7 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
|
||||
ShaderCreateInfoVertex *vert=mci->GetVS();
|
||||
|
||||
if(vert)
|
||||
mtl->primitive_render_buffer=GetVertexInput(vert->sdm->GetShaderStageIO().input);
|
||||
mtl->vertex_input=GetVertexInput(vert->sdm->GetShaderStageIO().input);
|
||||
}
|
||||
|
||||
{
|
||||
|
@@ -7,24 +7,20 @@
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
PrimitiveRenderBuffer::PrimitiveRenderBuffer(const uint32_t c,const uint32_t vc,const IBAccess *iba)
|
||||
PrimitiveDataBuffer::PrimitiveDataBuffer(const uint32_t c,const uint32_t vc, IndexBuffer *ib)
|
||||
{
|
||||
vab_count=c;
|
||||
|
||||
vab_list=hgl_zero_new<VkBuffer>(vab_count);
|
||||
|
||||
if(iba&&iba->buffer)
|
||||
ibo=iba->buffer;
|
||||
else
|
||||
ibo=nullptr;
|
||||
ibo=ib;
|
||||
}
|
||||
|
||||
PrimitiveRenderBuffer::~PrimitiveRenderBuffer()
|
||||
PrimitiveDataBuffer::~PrimitiveDataBuffer()
|
||||
{
|
||||
delete[] vab_list;
|
||||
}
|
||||
|
||||
const bool PrimitiveRenderBuffer::Comp(const PrimitiveRenderBuffer *prb)const
|
||||
const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *prb)const
|
||||
{
|
||||
if(!prb)return(false);
|
||||
|
||||
@@ -35,58 +31,41 @@ const bool PrimitiveRenderBuffer::Comp(const PrimitiveRenderBuffer *prb)const
|
||||
if(vab_list[i]!=prb->vab_list[i])return(false);
|
||||
}
|
||||
|
||||
if(ibo!=prb->ibo)return(false);
|
||||
if(ibo!=prb->ibo)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveRenderBuffer *prb,PrimitiveRenderData *prd)
|
||||
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *prb,PrimitiveRenderData *prd)
|
||||
{
|
||||
primitive=r;
|
||||
pipeline=p;
|
||||
mat_inst=mi;
|
||||
|
||||
primitive_render_buffer=prb;
|
||||
primitive_data_buffer=prb;
|
||||
primitive_render_data=prd;
|
||||
}
|
||||
|
||||
PrimitiveRenderData::PrimitiveRenderData(const uint32_t bc,const uint32_t vc,const IBAccess *iba)
|
||||
PrimitiveRenderData::PrimitiveRenderData(const uint32_t bc,const uint32_t vc)
|
||||
{
|
||||
vab_count=bc;
|
||||
|
||||
vab_offset=new VkDeviceSize[vab_count];
|
||||
|
||||
vertex_count=vc;
|
||||
vertex_offset=0;
|
||||
|
||||
if(iba&&iba->buffer)
|
||||
{
|
||||
index_start=iba->start;
|
||||
index_count=iba->count;
|
||||
}
|
||||
first_index=0;
|
||||
}
|
||||
|
||||
PrimitiveRenderData::~PrimitiveRenderData()
|
||||
{
|
||||
delete[] vab_offset;
|
||||
}
|
||||
|
||||
const bool PrimitiveRenderData::Comp(const PrimitiveRenderData *prd)const
|
||||
{
|
||||
if(!prd)return(false);
|
||||
|
||||
if(vab_count!=prd->vab_count)return(false);
|
||||
|
||||
for(uint i=0;i<vab_count;i++)
|
||||
{
|
||||
if(vab_offset[i]!=prd->vab_offset[i])return(false);
|
||||
}
|
||||
|
||||
if(vertex_count!=prd->vertex_count)return(false);
|
||||
|
||||
if(index_start!=prd->index_start)return(false);
|
||||
if(index_count!=prd->index_count)return(false);
|
||||
|
||||
return(true);
|
||||
return !memcmp(this,prd,sizeof(PrimitiveRenderData));
|
||||
}
|
||||
|
||||
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
@@ -104,10 +83,8 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
const IBAccess *iba=prim->GetIBAccess();
|
||||
|
||||
PrimitiveRenderBuffer * prb=new PrimitiveRenderBuffer( input_count,prim->GetVertexCount(),iba);
|
||||
PrimitiveRenderData * prd=new PrimitiveRenderData( input_count,prim->GetVertexCount(),iba);
|
||||
PrimitiveDataBuffer *prb=new PrimitiveDataBuffer(input_count,prim->GetVertexCount(),prim->GetIBO());
|
||||
PrimitiveRenderData *prd=new PrimitiveRenderData(input_count,prim->GetVertexCount());
|
||||
|
||||
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
||||
|
||||
@@ -146,7 +123,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
prd->vab_offset[i]=vab_access->start;
|
||||
prb->vab_offset[i]=vab_access->start;
|
||||
prb->vab_list[i]=vab_access->vab->GetBuffer();
|
||||
++vif;
|
||||
}
|
||||
|
Reference in New Issue
Block a user