create DrawData that it split from VertexInputData
This commit is contained in:
parent
a5e76988c7
commit
6740764f07
@ -225,7 +225,7 @@ public:
|
|||||||
cb->BindPipeline(ri->GetPipeline());
|
cb->BindPipeline(ri->GetPipeline());
|
||||||
cb->BindDescriptorSets(ri->GetMaterial());
|
cb->BindDescriptorSets(ri->GetMaterial());
|
||||||
cb->BindVBO(ri);
|
cb->BindVBO(ri);
|
||||||
cb->Draw(vid);
|
cb->Draw(vid,ri->GetDrawData());
|
||||||
cb->EndRenderPass();
|
cb->EndRenderPass();
|
||||||
cb->End();
|
cb->End();
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
#include<hgl/graph/VKVBOList.h>
|
#include<hgl/graph/VKVBOList.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class RenderL2WBuffer;
|
|
||||||
class RenderAssignBuffer;
|
class RenderAssignBuffer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同一材质的对象渲染列表
|
* 同一材质的对象渲染列表
|
||||||
*/
|
*/
|
||||||
@ -30,6 +30,7 @@ private:
|
|||||||
Pipeline * pipeline;
|
Pipeline * pipeline;
|
||||||
MaterialInstance * mi;
|
MaterialInstance * mi;
|
||||||
const VertexInputData * vid;
|
const VertexInputData * vid;
|
||||||
|
const DrawData * dd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -47,9 +48,10 @@ protected:
|
|||||||
|
|
||||||
Pipeline * last_pipeline;
|
Pipeline * last_pipeline;
|
||||||
const VertexInputData * last_vid;
|
const VertexInputData * last_vid;
|
||||||
|
const DrawData * last_dd;
|
||||||
uint last_index;
|
uint last_index;
|
||||||
|
|
||||||
bool Bind(const VertexInputData *,const uint);
|
bool BindVAB(const VertexInputData *,const DrawData *,const uint);
|
||||||
|
|
||||||
void Render(RenderItem *);
|
void Render(RenderItem *);
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class DeviceBuffer;
|
|||||||
struct DeviceBufferData;
|
struct DeviceBufferData;
|
||||||
|
|
||||||
struct VertexInputData;
|
struct VertexInputData;
|
||||||
|
struct DrawData;
|
||||||
|
|
||||||
class VertexAttribBuffer;
|
class VertexAttribBuffer;
|
||||||
using VAB=VertexAttribBuffer;
|
using VAB=VertexAttribBuffer;
|
||||||
|
@ -165,12 +165,12 @@ public:
|
|||||||
|
|
||||||
if(!vbo_list->IsFull())return(false);
|
if(!vbo_list->IsFull())return(false);
|
||||||
|
|
||||||
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
|
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->vab_count,vbo_list->vab_list,vbo_list->vab_offset);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void BindIBO(const IBAccess *);
|
void BindIBO(IndexBuffer *ibo,VkDeviceSize offset); ///<绑定IBO,注意offset意为索引偏移量,不是字节
|
||||||
|
|
||||||
bool BindVBO(Renderable *);
|
bool BindVBO(Renderable *);
|
||||||
|
|
||||||
@ -200,8 +200,8 @@ public: //draw
|
|||||||
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
||||||
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
||||||
|
|
||||||
void Draw (const VertexInputData *vid);
|
void Draw (const VertexInputData *vid,const DrawData *dd);
|
||||||
void DrawIndexed (const IBAccess *iba,const uint32_t instance_count);
|
// void DrawIndexed (const IBAccess *iba,const uint32_t instance_count);
|
||||||
|
|
||||||
public: //dynamic state
|
public: //dynamic state
|
||||||
};//class RenderCmdBuffer:public GPUCmdBuffer
|
};//class RenderCmdBuffer:public GPUCmdBuffer
|
||||||
|
@ -11,12 +11,12 @@ class DeviceBuffer;
|
|||||||
class DescriptorSet
|
class DescriptorSet
|
||||||
{
|
{
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
int binding_count;
|
int vab_count;
|
||||||
VkDescriptorSet desc_set;
|
VkDescriptorSet desc_set;
|
||||||
|
|
||||||
VkPipelineLayout pipeline_layout;
|
VkPipelineLayout pipeline_layout;
|
||||||
|
|
||||||
ObjectList<VkDescriptorBufferInfo> buffer_list;
|
ObjectList<VkDescriptorBufferInfo> vab_list;
|
||||||
ObjectList<VkDescriptorImageInfo> image_list;
|
ObjectList<VkDescriptorImageInfo> image_list;
|
||||||
List<VkWriteDescriptorSet> wds_list;
|
List<VkWriteDescriptorSet> wds_list;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ public:
|
|||||||
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
|
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
|
||||||
{
|
{
|
||||||
device =dev;
|
device =dev;
|
||||||
binding_count =bc;
|
vab_count =bc;
|
||||||
desc_set =ds;
|
desc_set =ds;
|
||||||
pipeline_layout =pl;
|
pipeline_layout =pl;
|
||||||
|
|
||||||
@ -38,11 +38,11 @@ public:
|
|||||||
|
|
||||||
~DescriptorSet()=default;
|
~DescriptorSet()=default;
|
||||||
|
|
||||||
const uint32_t GetCount ()const{return binding_count;}
|
const uint32_t GetCount ()const{return vab_count;}
|
||||||
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
|
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
|
||||||
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
||||||
|
|
||||||
const bool IsReady ()const{return wds_list.GetCount()==binding_count;}
|
const bool IsReady ()const{return wds_list.GetCount()==vab_count;}
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class Material
|
|||||||
{
|
{
|
||||||
AnsiString name;
|
AnsiString name;
|
||||||
|
|
||||||
VertexInput *vertex_input;
|
VertexInput *vertex_input_data;
|
||||||
|
|
||||||
ShaderModuleMap *shader_maps;
|
ShaderModuleMap *shader_maps;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public:
|
|||||||
|
|
||||||
const AnsiString & GetName ()const{return name;}
|
const AnsiString & GetName ()const{return name;}
|
||||||
|
|
||||||
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
const VertexInput * GetVertexInput ()const{return vertex_input_data;}
|
||||||
|
|
||||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||||
|
|
||||||
|
@ -40,10 +40,13 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
const AnsiString & GetName ()const{ return prim_name; }
|
const AnsiString & GetName ()const{ return prim_name; }
|
||||||
|
|
||||||
const VkDeviceSize GetVertexCount ()const;
|
const VkDeviceSize GetVertexCount ()const;
|
||||||
const int GetVABCount ()const;
|
const int GetVABCount ()const;
|
||||||
VABAccess * GetVABAccess (const AnsiString &);
|
VABAccess * GetVABAccess (const AnsiString &);
|
||||||
|
|
||||||
IBAccess * GetIBAccess ();
|
IBAccess * GetIBAccess ();
|
||||||
|
IndexBuffer * GetIBO ();
|
||||||
|
|
||||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||||
};//class Primitive
|
};//class Primitive
|
||||||
|
@ -11,39 +11,35 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
struct VertexInputData
|
struct VertexInputData
|
||||||
{
|
{
|
||||||
uint32_t binding_count;
|
uint32_t vab_count;
|
||||||
VkBuffer *buffer_list;
|
VkBuffer *vab_list;
|
||||||
VkDeviceSize *buffer_offset;
|
IndexBuffer *ibo;
|
||||||
|
|
||||||
uint32_t vertex_count;
|
|
||||||
|
|
||||||
const IBAccess *ib_access;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VertexInputData(const uint32_t,const uint32_t,const IBAccess *);
|
VertexInputData(const uint32_t,const uint32_t,const IBAccess *iba);
|
||||||
~VertexInputData();
|
~VertexInputData();
|
||||||
|
|
||||||
const bool Comp(const VertexInputData *vid)const
|
const bool Comp(const VertexInputData *vid)const;
|
||||||
{
|
|
||||||
if(!vid)return(false);
|
|
||||||
|
|
||||||
if(binding_count!=vid->binding_count)return(false);
|
|
||||||
|
|
||||||
for(uint32_t i=0;i<binding_count;i++)
|
|
||||||
{
|
|
||||||
if(buffer_list[i]!=vid->buffer_list[i])return(false);
|
|
||||||
if(buffer_offset[i]!=vid->buffer_offset[i])return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(vertex_count!=vid->vertex_count)return(false);
|
|
||||||
|
|
||||||
if(ib_access!=vid->ib_access)return(false);
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
};//struct VertexInputData
|
};//struct VertexInputData
|
||||||
|
|
||||||
|
struct DrawData
|
||||||
|
{
|
||||||
|
uint vab_count;
|
||||||
|
VkDeviceSize * vab_offset;
|
||||||
|
VkDeviceSize vertex_count;
|
||||||
|
|
||||||
|
VkDeviceSize index_start;
|
||||||
|
VkDeviceSize index_count;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
DrawData(const uint32_t bc,const VkDeviceSize vc,const IBAccess *iba);
|
||||||
|
~DrawData();
|
||||||
|
|
||||||
|
const bool Comp(const DrawData *)const;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可渲染对象<br>
|
* 可渲染对象<br>
|
||||||
*/
|
*/
|
||||||
@ -53,17 +49,24 @@ class Renderable
|
|||||||
MaterialInstance * mat_inst;
|
MaterialInstance * mat_inst;
|
||||||
Primitive * primitive;
|
Primitive * primitive;
|
||||||
|
|
||||||
VertexInputData * vertex_input;
|
VertexInputData * vertex_input_data;
|
||||||
|
DrawData * draw_data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||||
|
|
||||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
|
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *,DrawData *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Renderable();
|
virtual ~Renderable()
|
||||||
|
{
|
||||||
|
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||||
|
|
||||||
|
SAFE_CLEAR(vertex_input_data);
|
||||||
|
SAFE_CLEAR(draw_data);
|
||||||
|
}
|
||||||
|
|
||||||
void UpdatePipeline (Pipeline *p){pipeline=p;}
|
void UpdatePipeline (Pipeline *p){pipeline=p;}
|
||||||
|
|
||||||
@ -74,7 +77,8 @@ 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;}
|
const VertexInputData * GetVertexInputData ()const{return vertex_input_data;}
|
||||||
|
const DrawData * GetDrawData ()const{return draw_data;}
|
||||||
};//class Renderable
|
};//class Renderable
|
||||||
|
|
||||||
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class VBOList
|
class VBOList
|
||||||
{
|
{
|
||||||
uint32_t binding_count;
|
uint32_t vab_count;
|
||||||
VkBuffer *buffer_list;
|
VkBuffer *vab_list;
|
||||||
VkDeviceSize *buffer_offset;
|
VkDeviceSize *vab_offset;
|
||||||
|
|
||||||
uint32_t write_count;
|
uint32_t write_count;
|
||||||
|
|
||||||
@ -15,17 +15,17 @@ public:
|
|||||||
|
|
||||||
VBOList(const uint32 bc)
|
VBOList(const uint32 bc)
|
||||||
{
|
{
|
||||||
binding_count=bc;
|
vab_count=bc;
|
||||||
buffer_list=new VkBuffer[binding_count];
|
vab_list=new VkBuffer[vab_count];
|
||||||
buffer_offset=new VkDeviceSize[binding_count];
|
vab_offset=new VkDeviceSize[vab_count];
|
||||||
|
|
||||||
write_count=0;
|
write_count=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~VBOList()
|
~VBOList()
|
||||||
{
|
{
|
||||||
delete[] buffer_offset;
|
delete[] vab_offset;
|
||||||
delete[] buffer_list;
|
delete[] vab_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Restart()
|
void Restart()
|
||||||
@ -35,21 +35,21 @@ public:
|
|||||||
|
|
||||||
const bool IsFull()const
|
const bool IsFull()const
|
||||||
{
|
{
|
||||||
return write_count>=binding_count;
|
return write_count>=vab_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Add(const VkBuffer buf,const VkDeviceSize offset)
|
void Add(const VkBuffer buf,const VkDeviceSize offset)
|
||||||
{
|
{
|
||||||
buffer_list[write_count]=buf;
|
vab_list[write_count]=buf;
|
||||||
buffer_offset[write_count]=offset;
|
vab_offset[write_count]=offset;
|
||||||
|
|
||||||
++write_count;
|
++write_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
|
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
|
||||||
{
|
{
|
||||||
hgl_cpy(buffer_list +write_count,buf, count);
|
hgl_cpy(vab_list +write_count,buf, count);
|
||||||
hgl_cpy(buffer_offset+write_count,offset,count);
|
hgl_cpy(vab_offset+write_count,offset,count);
|
||||||
|
|
||||||
write_count+=count;
|
write_count+=count;
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,7 @@ void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
|||||||
pipeline =ri->GetPipeline();
|
pipeline =ri->GetPipeline();
|
||||||
mi =ri->GetMaterialInstance();
|
mi =ri->GetMaterialInstance();
|
||||||
vid =ri->GetVertexInputData();
|
vid =ri->GetVertexInputData();
|
||||||
|
dd =ri->GetDrawData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialRenderList::Stat()
|
void MaterialRenderList::Stat()
|
||||||
@ -114,6 +115,7 @@ void MaterialRenderList::Stat()
|
|||||||
|
|
||||||
last_pipeline =ri->pipeline;
|
last_pipeline =ri->pipeline;
|
||||||
last_vid =ri->vid;
|
last_vid =ri->vid;
|
||||||
|
last_dd =ri->dd;
|
||||||
|
|
||||||
++rn;
|
++rn;
|
||||||
|
|
||||||
@ -121,6 +123,7 @@ void MaterialRenderList::Stat()
|
|||||||
{
|
{
|
||||||
if(last_pipeline==rn->ri->GetPipeline())
|
if(last_pipeline==rn->ri->GetPipeline())
|
||||||
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
if(last_vid->Comp(rn->ri->GetVertexInputData()))
|
||||||
|
if(last_dd->Comp(rn->ri->GetDrawData()))
|
||||||
{
|
{
|
||||||
++ri->count;
|
++ri->count;
|
||||||
++rn;
|
++rn;
|
||||||
@ -136,25 +139,26 @@ void MaterialRenderList::Stat()
|
|||||||
|
|
||||||
last_pipeline =ri->pipeline;
|
last_pipeline =ri->pipeline;
|
||||||
last_vid =ri->vid;
|
last_vid =ri->vid;
|
||||||
|
last_dd =ri->dd;
|
||||||
|
|
||||||
++rn;
|
++rn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
bool MaterialRenderList::BindVAB(const VertexInputData *vid,const DrawData *dd,const uint ri_index)
|
||||||
{
|
{
|
||||||
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
||||||
|
|
||||||
//const VIL *vil=last_vil;
|
//const VIL *vil=last_vil;
|
||||||
|
|
||||||
//if(vil->GetCount(VertexInputGroup::Basic)!=vid->binding_count)
|
//if(vil->GetCount(VertexInputGroup::Basic)!=vid->vab_count)
|
||||||
// return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
// return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
||||||
|
|
||||||
vbo_list->Restart();
|
vbo_list->Restart();
|
||||||
|
|
||||||
//Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来
|
//Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来
|
||||||
{
|
{
|
||||||
vbo_list->Add(vid->buffer_list,vid->buffer_offset,vid->binding_count);
|
vbo_list->Add(vid->vab_list,dd->vab_offset,vid->vab_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(assign_buffer) //L2W/MI分发组
|
if(assign_buffer) //L2W/MI分发组
|
||||||
@ -168,7 +172,7 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
|||||||
// {
|
// {
|
||||||
// count+=joint_id_binding_count;
|
// count+=joint_id_binding_count;
|
||||||
|
|
||||||
// if(count<binding_count) //JointWeight组
|
// if(count<vab_count) //JointWeight组
|
||||||
// {
|
// {
|
||||||
// const uint joing_weight_binding_count=vil->GetCount(VertexInputGroup::JointWeight);
|
// const uint joing_weight_binding_count=vil->GetCount(VertexInputGroup::JointWeight);
|
||||||
|
|
||||||
@ -188,7 +192,7 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//if(count!=binding_count)
|
//if(count!=vab_count)
|
||||||
//{
|
//{
|
||||||
// //还有没支持的绑定组????
|
// //还有没支持的绑定组????
|
||||||
|
|
||||||
@ -214,17 +218,24 @@ void MaterialRenderList::Render(RenderItem *ri)
|
|||||||
|
|
||||||
if(!ri->vid->Comp(last_vid))
|
if(!ri->vid->Comp(last_vid))
|
||||||
{
|
{
|
||||||
Bind(ri->vid,ri->first);
|
|
||||||
last_vid=ri->vid;
|
last_vid=ri->vid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(last_vid->ib_access)
|
if(!ri->dd->Comp(last_dd))
|
||||||
{
|
{
|
||||||
cmd_buf->DrawIndexed(last_vid->ib_access,ri->count);
|
BindVAB(ri->vid,ri->dd,ri->first);
|
||||||
|
last_dd=ri->dd;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(last_vid->ibo)
|
||||||
|
{
|
||||||
|
cmd_buf->BindIBO(ri->vid->ibo,ri->dd->index_start);
|
||||||
|
cmd_buf->DrawIndexed(ri->dd->index_count,
|
||||||
|
ri->count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd_buf->Draw(last_vid->vertex_count,ri->count);
|
cmd_buf->Draw(ri->dd->vertex_count,ri->count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +130,13 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void RenderCmdBuffer::BindIBO(const IBAccess *iba)
|
void RenderCmdBuffer::BindIBO(IndexBuffer *ibo,VkDeviceSize offset)
|
||||||
//{
|
{
|
||||||
// vkCmdBindIndexBuffer( cmd_buf,
|
vkCmdBindIndexBuffer(cmd_buf,
|
||||||
// iba->buffer->GetBuffer(),
|
ibo->GetBuffer(),
|
||||||
// iba->start,
|
offset*ibo->GetStride(),
|
||||||
// VkIndexType(iba->buffer->GetType()));
|
VkIndexType(ibo->GetType()));
|
||||||
//}
|
}
|
||||||
|
|
||||||
bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
||||||
{
|
{
|
||||||
@ -145,18 +145,18 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
|||||||
|
|
||||||
const VertexInputData *vid=ri->GetVertexInputData();
|
const VertexInputData *vid=ri->GetVertexInputData();
|
||||||
|
|
||||||
if(vid->binding_count<=0)
|
if(vid->vab_count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
vkCmdBindVertexBuffers(cmd_buf,0,vid->binding_count,vid->buffer_list,vid->buffer_offset);
|
const DrawData *dd=ri->GetDrawData();
|
||||||
|
|
||||||
IndexBuffer *indices_buffer=vid->ib_access->buffer;
|
if(dd->vertex_count<=0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(indices_buffer)
|
vkCmdBindVertexBuffers(cmd_buf,0,vid->vab_count,vid->vab_list,dd->vab_offset);
|
||||||
vkCmdBindIndexBuffer(cmd_buf,
|
|
||||||
indices_buffer->GetBuffer(),
|
if(vid->ibo&&dd->index_count)
|
||||||
vid->ib_access->start,
|
BindIBO(vid->ibo,dd->index_start);
|
||||||
VkIndexType(indices_buffer->GetType()));
|
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -185,23 +185,31 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer,
|
|||||||
vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride);
|
vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderCmdBuffer::Draw(const VertexInputData *vid)
|
void RenderCmdBuffer::Draw(const VertexInputData *vid,const DrawData *dd)
|
||||||
{
|
{
|
||||||
if (vid->ib_access->buffer)
|
if(!vid||!dd)
|
||||||
DrawIndexed(vid->ib_access->count);
|
return;
|
||||||
|
|
||||||
|
if (vid->ibo)
|
||||||
|
DrawIndexed(dd->index_count);
|
||||||
else
|
else
|
||||||
Draw(vid->vertex_count);
|
Draw(dd->vertex_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count)
|
//void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count)
|
||||||
{
|
//{
|
||||||
if(!iba||instance_count<=0)return;
|
// if(!iba||instance_count<=0)return;
|
||||||
|
//
|
||||||
vkCmdBindIndexBuffer(cmd_buf,
|
// vkCmdBindIndexBuffer(cmd_buf,
|
||||||
iba->buffer->GetBuffer(),
|
// iba->buffer->GetBuffer(),
|
||||||
iba->start*iba->buffer->GetStride(),
|
// iba->start*iba->buffer->GetStride(),
|
||||||
VkIndexType(iba->buffer->GetType()));
|
// VkIndexType(iba->buffer->GetType()));
|
||||||
|
//
|
||||||
vkCmdDrawIndexed(cmd_buf,iba->count,instance_count,0,0,0);
|
// vkCmdDrawIndexed(cmd_buf,
|
||||||
}
|
// iba->count,
|
||||||
|
// instance_count,
|
||||||
|
// 0, //first index
|
||||||
|
// 0, //vertex offset
|
||||||
|
// 0); //first instance
|
||||||
|
//}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -69,7 +69,7 @@ namespace
|
|||||||
|
|
||||||
void DescriptorSet::Clear()
|
void DescriptorSet::Clear()
|
||||||
{
|
{
|
||||||
buffer_list.Clear();
|
vab_list.Clear();
|
||||||
image_list.Clear();
|
image_list.Clear();
|
||||||
wds_list.Clear();
|
wds_list.Clear();
|
||||||
binded_sets.Clear();
|
binded_sets.Clear();
|
||||||
@ -101,7 +101,7 @@ bool DescriptorSet::BindUBO(const int binding,const DeviceBuffer *buf,const VkDe
|
|||||||
|
|
||||||
DescriptorBufferInfo *buf_info=new DescriptorBufferInfo(buf,offset,range);
|
DescriptorBufferInfo *buf_info=new DescriptorBufferInfo(buf,offset,range);
|
||||||
|
|
||||||
buffer_list.Add(buf_info);
|
vab_list.Add(buf_info);
|
||||||
|
|
||||||
const VkDescriptorType desc_type=dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
const VkDescriptorType desc_type=dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ bool DescriptorSet::BindSSBO(const int binding,const DeviceBuffer *buf,const VkD
|
|||||||
|
|
||||||
DescriptorBufferInfo *buf_info=new DescriptorBufferInfo(buf,offset,range);
|
DescriptorBufferInfo *buf_info=new DescriptorBufferInfo(buf,offset,range);
|
||||||
|
|
||||||
buffer_list.Add(buf_info);
|
vab_list.Add(buf_info);
|
||||||
|
|
||||||
const VkDescriptorType desc_type=dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
const VkDescriptorType desc_type=dynamic?VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ namespace
|
|||||||
{
|
{
|
||||||
RANGE_CHECK_RETURN_NULLPTR(type);
|
RANGE_CHECK_RETURN_NULLPTR(type);
|
||||||
|
|
||||||
const uint32_t binding_count=pld->binding_count[size_t(type)];
|
const uint32_t vab_count=pld->vab_count[size_t(type)];
|
||||||
|
|
||||||
if(!binding_count)
|
if(!vab_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
DescriptorSetAllocateInfo alloc_info;
|
DescriptorSetAllocateInfo alloc_info;
|
||||||
@ -34,7 +34,7 @@ namespace
|
|||||||
if(vkAllocateDescriptorSets(device,&alloc_info,&desc_set)!=VK_SUCCESS)
|
if(vkAllocateDescriptorSets(device,&alloc_info,&desc_set)!=VK_SUCCESS)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return(new DescriptorSet(device,binding_count,pld->pipeline_layout,desc_set));
|
return(new DescriptorSet(device,vab_count,pld->pipeline_layout,desc_set));
|
||||||
}
|
}
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ Material::Material(const AnsiString &n)
|
|||||||
{
|
{
|
||||||
name=n;
|
name=n;
|
||||||
|
|
||||||
vertex_input=nullptr;
|
vertex_input_data=nullptr;
|
||||||
shader_maps=new ShaderModuleMap;
|
shader_maps=new ShaderModuleMap;
|
||||||
desc_manager=nullptr;
|
desc_manager=nullptr;
|
||||||
pipeline_layout_data=nullptr;
|
pipeline_layout_data=nullptr;
|
||||||
@ -28,7 +28,7 @@ Material::~Material()
|
|||||||
{
|
{
|
||||||
SAFE_CLEAR(mi_data_manager);
|
SAFE_CLEAR(mi_data_manager);
|
||||||
|
|
||||||
ReleaseVertexInput(vertex_input);
|
ReleaseVertexInput(vertex_input_data);
|
||||||
delete shader_maps; //不用SAFE_CLEAR是因为这个一定会有
|
delete shader_maps; //不用SAFE_CLEAR是因为这个一定会有
|
||||||
SAFE_CLEAR(desc_manager);
|
SAFE_CLEAR(desc_manager);
|
||||||
SAFE_CLEAR(pipeline_layout_data);
|
SAFE_CLEAR(pipeline_layout_data);
|
||||||
@ -49,22 +49,22 @@ const bool Material::hasSet(const DescriptorSetType &dst)const
|
|||||||
|
|
||||||
const VIL *Material::GetDefaultVIL()const
|
const VIL *Material::GetDefaultVIL()const
|
||||||
{
|
{
|
||||||
return vertex_input->GetDefaultVIL();
|
return vertex_input_data->GetDefaultVIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
VIL *Material::CreateVIL(const VILConfig *format_map)
|
VIL *Material::CreateVIL(const VILConfig *format_map)
|
||||||
{
|
{
|
||||||
return vertex_input->CreateVIL(format_map);
|
return vertex_input_data->CreateVIL(format_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Material::Release(VIL *vil)
|
bool Material::Release(VIL *vil)
|
||||||
{
|
{
|
||||||
return vertex_input->Release(vil);
|
return vertex_input_data->Release(vil);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint Material::GetVILCount()
|
const uint Material::GetVILCount()
|
||||||
{
|
{
|
||||||
return vertex_input->GetInstanceCount();
|
return vertex_input_data->GetInstanceCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Material::BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
bool Material::BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
||||||
|
@ -26,7 +26,7 @@ PipelineLayoutData *GPUDevice::CreatePipelineLayoutData(const MaterialDescriptor
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pld->binding_count[i]=dslci->bindingCount;
|
pld->vab_count[i]=dslci->bindingCount;
|
||||||
|
|
||||||
pld->fin_dsl[pld->fin_dsl_count]=pld->layouts[i];
|
pld->fin_dsl[pld->fin_dsl_count]=pld->layouts[i];
|
||||||
++pld->fin_dsl_count;
|
++pld->fin_dsl_count;
|
||||||
|
@ -9,7 +9,7 @@ struct PipelineLayoutData
|
|||||||
{
|
{
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
|
|
||||||
int binding_count[DESCRIPTOR_SET_TYPE_COUNT];
|
int vab_count[DESCRIPTOR_SET_TYPE_COUNT];
|
||||||
VkDescriptorSetLayout layouts[DESCRIPTOR_SET_TYPE_COUNT];
|
VkDescriptorSetLayout layouts[DESCRIPTOR_SET_TYPE_COUNT];
|
||||||
|
|
||||||
VkDescriptorSetLayout fin_dsl[DESCRIPTOR_SET_TYPE_COUNT];
|
VkDescriptorSetLayout fin_dsl[DESCRIPTOR_SET_TYPE_COUNT];
|
||||||
|
@ -61,4 +61,9 @@ IBAccess *Primitive::GetIBAccess()
|
|||||||
return prim_data->GetIBAccess();
|
return prim_data->GetIBAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IndexBuffer *Primitive::GetIBO()
|
||||||
|
{
|
||||||
|
return prim_data->GetIBO();
|
||||||
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -38,7 +38,9 @@ public:
|
|||||||
const int GetVABIndex (const AnsiString &name)const;
|
const int GetVABIndex (const AnsiString &name)const;
|
||||||
VABAccess * GetVABAccess (const int index);
|
VABAccess * GetVABAccess (const int index);
|
||||||
VABAccess * GetVABAccess (const AnsiString &name);
|
VABAccess * GetVABAccess (const AnsiString &name);
|
||||||
|
|
||||||
IBAccess * GetIBAccess (){return &ib_access;}
|
IBAccess * GetIBAccess (){return &ib_access;}
|
||||||
|
IndexBuffer * GetIBO (){return ib_access.buffer;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
|
|||||||
ShaderCreateInfoVertex *vert=mci->GetVS();
|
ShaderCreateInfoVertex *vert=mci->GetVS();
|
||||||
|
|
||||||
if(vert)
|
if(vert)
|
||||||
mtl->vertex_input=GetVertexInput(vert->sdm->GetShaderStageIO().input);
|
mtl->vertex_input_data=GetVertexInput(vert->sdm->GetShaderStageIO().input);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -3,44 +3,90 @@
|
|||||||
#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/graph/VKIndexBuffer.h>
|
||||||
#include<hgl/log/LogInfo.h>
|
#include<hgl/log/LogInfo.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IBAccess *iba)
|
VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IBAccess *iba)
|
||||||
{
|
{
|
||||||
binding_count=c;
|
vab_count=c;
|
||||||
|
|
||||||
buffer_list=new VkBuffer[binding_count];
|
vab_list=hgl_zero_new<VkBuffer>(vab_count);
|
||||||
buffer_offset=new VkDeviceSize[binding_count];
|
|
||||||
|
|
||||||
vertex_count=vc;
|
if(iba&&iba->buffer)
|
||||||
|
ibo=iba->buffer;
|
||||||
if(!iba||!iba->buffer)
|
|
||||||
ib_access=nullptr;
|
|
||||||
else
|
else
|
||||||
ib_access=iba;
|
ibo=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexInputData::~VertexInputData()
|
VertexInputData::~VertexInputData()
|
||||||
{
|
{
|
||||||
delete[] buffer_list;
|
delete[] vab_list;
|
||||||
delete[] buffer_offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vi)
|
const bool VertexInputData::Comp(const VertexInputData *vid)const
|
||||||
|
{
|
||||||
|
if(!vid)return(false);
|
||||||
|
|
||||||
|
if(vab_count!=vid->vab_count)return(false);
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<vab_count;i++)
|
||||||
|
{
|
||||||
|
if(vab_list[i]!=vid->vab_list[i])return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ibo!=vid->ibo)return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vid,DrawData *dd)
|
||||||
{
|
{
|
||||||
primitive=r;
|
primitive=r;
|
||||||
pipeline=p;
|
pipeline=p;
|
||||||
mat_inst=mi;
|
mat_inst=mi;
|
||||||
|
|
||||||
vertex_input=vi;
|
vertex_input_data=vid;
|
||||||
|
draw_data=dd;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable::~Renderable()
|
DrawData::DrawData(const uint32_t bc,const VkDeviceSize vc,const IBAccess *iba)
|
||||||
{
|
{
|
||||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
vab_count=bc;
|
||||||
|
|
||||||
delete vertex_input;
|
vab_offset=new VkDeviceSize[vab_count];
|
||||||
|
|
||||||
|
vertex_count=vc;
|
||||||
|
|
||||||
|
if(iba&&iba->buffer)
|
||||||
|
{
|
||||||
|
index_start=iba->start;
|
||||||
|
index_count=iba->count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawData::~DrawData()
|
||||||
|
{
|
||||||
|
delete[] vab_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool DrawData::Comp(const DrawData *dd)const
|
||||||
|
{
|
||||||
|
if(!dd)return(false);
|
||||||
|
|
||||||
|
if(vab_count!=dd->vab_count)return(false);
|
||||||
|
|
||||||
|
for(uint i=0;i<vab_count;i++)
|
||||||
|
{
|
||||||
|
if(vab_offset[i]!=dd->vab_offset[i])return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(vertex_count!=dd->vertex_count)return(false);
|
||||||
|
|
||||||
|
if(index_start!=dd->index_start)return(false);
|
||||||
|
if(index_count!=dd->index_count)return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||||
@ -58,7 +104,10 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIBAccess());
|
const IBAccess *iba=prim->GetIBAccess();
|
||||||
|
|
||||||
|
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),iba);
|
||||||
|
DrawData *dd=new DrawData(input_count,prim->GetVertexCount(),iba);
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
||||||
VABAccess *vab_access;
|
VABAccess *vab_access;
|
||||||
@ -96,11 +145,11 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
vid->buffer_offset[i]=vab_access->start*vif->stride;
|
dd->vab_offset[i]=vab_access->start*vif->stride;
|
||||||
vid->buffer_list[i]=vab_access->vab->GetBuffer();
|
vid->vab_list[i]=vab_access->vab->GetBuffer();
|
||||||
++vif;
|
++vif;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(new Renderable(prim,mi,p,vid));
|
return(new Renderable(prim,mi,p,vid,dd));
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user