2023-06-01 15:08:45 +08:00
|
|
|
|
#include<hgl/graph/MaterialRenderList.h>
|
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/VKCommandBuffer.h>
|
|
|
|
|
#include<hgl/graph/VKVertexInput.h>
|
2023-09-06 16:55:04 +08:00
|
|
|
|
#include<hgl/graph/VKRenderAssign.h>
|
2023-06-01 15:08:45 +08:00
|
|
|
|
#include<hgl/util/sort/Sort.h>
|
2023-09-05 20:48:47 +08:00
|
|
|
|
#include"RenderAssignBuffer.h"
|
2024-05-28 23:49:28 +08:00
|
|
|
|
#include<hgl/graph/VertexDataManager.h>
|
2024-07-18 01:53:23 +08:00
|
|
|
|
#include<hgl/graph/SceneNode.h>
|
2024-08-02 23:17:07 +08:00
|
|
|
|
#include<hgl/graph/CameraInfo.h>
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 理论上讲,我们需要按以下顺序排序
|
|
|
|
|
*
|
|
|
|
|
* for(material)
|
|
|
|
|
* for(pipeline)
|
|
|
|
|
* for(material_instance)
|
2024-04-24 01:38:55 +08:00
|
|
|
|
* for(vab)
|
2024-05-30 13:14:13 +08:00
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* 关于Indirect Command Buffer
|
|
|
|
|
|
|
|
|
|
建立一个大的IndirectCommandBuffer,用于存放所有的渲染指令,包括那些不能使用Indirect渲染的。
|
|
|
|
|
这样就可以保证所有的渲染操作就算要切VBO,也不需要切换INDIRECT缓冲区,定位指令也很方便。
|
2023-06-01 15:08:45 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
const int RenderNode::compare(const RenderNode &other)const
|
2023-06-01 15:08:45 +08:00
|
|
|
|
{
|
2024-05-28 23:49:28 +08:00
|
|
|
|
hgl::int64 off;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
hgl::graph::Renderable *ri_one=other.scene_node->GetRenderable();
|
|
|
|
|
hgl::graph::Renderable *ri_two=scene_node->GetRenderable();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-28 23:49:28 +08:00
|
|
|
|
auto *prim_one=ri_one->GetPrimitive();
|
|
|
|
|
auto *prim_two=ri_two->GetPrimitive();
|
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
//比较VDM
|
|
|
|
|
|
|
|
|
|
if(prim_one->GetVDM()) //有VDM
|
2024-05-28 23:49:28 +08:00
|
|
|
|
{
|
|
|
|
|
off=prim_one->GetVDM()
|
|
|
|
|
-prim_two->GetVDM();
|
|
|
|
|
|
|
|
|
|
if(off)
|
|
|
|
|
return off;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
//比较模型
|
2024-05-28 23:49:28 +08:00
|
|
|
|
{
|
2024-08-02 23:17:07 +08:00
|
|
|
|
off=prim_one
|
|
|
|
|
-prim_two;
|
2024-05-28 23:49:28 +08:00
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
if(off)
|
|
|
|
|
{
|
|
|
|
|
off=prim_one->GetVertexOffset()-prim_two->GetVertexOffset(); //保证vertex offset小的在前面
|
|
|
|
|
|
|
|
|
|
return off;
|
|
|
|
|
}
|
2024-05-28 23:49:28 +08:00
|
|
|
|
}
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
//比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
float foff=other.to_camera_distance
|
|
|
|
|
-to_camera_distance;
|
2024-08-02 23:17:07 +08:00
|
|
|
|
|
|
|
|
|
if(foff>0)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi)
|
2023-06-01 15:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
device=d;
|
|
|
|
|
cmd_buf=nullptr;
|
2025-01-15 02:42:04 +08:00
|
|
|
|
rp_index=rpi;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
camera_info=nullptr;
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
assign_buffer=new RenderAssignBuffer(device,rp_index.material);
|
2023-10-12 02:24:58 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
vab_list=new VABList(rp_index.material->GetVertexInput()->GetCount());
|
2024-05-30 13:14:13 +08:00
|
|
|
|
|
|
|
|
|
icb_draw=nullptr;
|
|
|
|
|
icb_draw_indexed=nullptr;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaterialRenderList::~MaterialRenderList()
|
|
|
|
|
{
|
2024-05-30 13:14:13 +08:00
|
|
|
|
SAFE_CLEAR(icb_draw_indexed)
|
|
|
|
|
SAFE_CLEAR(icb_draw)
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
SAFE_CLEAR(vab_list);
|
2024-05-25 17:58:39 +08:00
|
|
|
|
SAFE_CLEAR(assign_buffer);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 01:53:23 +08:00
|
|
|
|
void MaterialRenderList::Add(SceneNode *sn)
|
2023-06-01 15:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
RenderNode rn;
|
|
|
|
|
|
2024-08-30 03:36:01 +08:00
|
|
|
|
rn.index =rn_list.GetCount();
|
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
rn.scene_node =sn;
|
|
|
|
|
|
2024-08-30 03:36:01 +08:00
|
|
|
|
rn.l2w_version =sn->GetLocalToWorldMatrixVersion();
|
|
|
|
|
rn.l2w_index =0;
|
2024-08-04 22:35:31 +08:00
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
rn.world_position =sn->GetWorldPosition();
|
|
|
|
|
|
|
|
|
|
if(camera_info)
|
|
|
|
|
rn.to_camera_distance=length(camera_info->pos,rn.world_position);
|
|
|
|
|
else
|
|
|
|
|
rn.to_camera_distance=0;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
rn_list.Add(rn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialRenderList::End()
|
|
|
|
|
{
|
|
|
|
|
//排序
|
2023-07-28 20:41:02 +08:00
|
|
|
|
Sort(rn_list.GetArray());
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2023-06-01 21:25:50 +08:00
|
|
|
|
const uint node_count=rn_list.GetCount();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2023-06-01 21:25:50 +08:00
|
|
|
|
if(node_count<=0)return;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
Stat();
|
2023-06-01 21:25:50 +08:00
|
|
|
|
|
2024-05-25 17:58:39 +08:00
|
|
|
|
if(assign_buffer)
|
|
|
|
|
assign_buffer->WriteNode(rn_list);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 01:27:53 +08:00
|
|
|
|
void MaterialRenderList::UpdateLocalToWorld()
|
2024-08-04 22:35:31 +08:00
|
|
|
|
{
|
|
|
|
|
if(!assign_buffer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rn_update_l2w_list.Clear();
|
|
|
|
|
|
|
|
|
|
const int node_count=rn_list.GetCount();
|
|
|
|
|
|
|
|
|
|
if(node_count<=0)return;
|
|
|
|
|
|
|
|
|
|
int first=-1,last=-1;
|
|
|
|
|
int update_count=0;
|
2024-08-27 01:27:53 +08:00
|
|
|
|
uint32 l2w_version=0;
|
2024-08-04 22:35:31 +08:00
|
|
|
|
RenderNode *rn=rn_list.GetData();
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<node_count;i++)
|
|
|
|
|
{
|
2024-08-27 01:27:53 +08:00
|
|
|
|
l2w_version=rn->scene_node->GetLocalToWorldMatrixVersion();
|
2024-08-04 22:35:31 +08:00
|
|
|
|
|
2024-08-27 01:27:53 +08:00
|
|
|
|
if(rn->l2w_version!=l2w_version) //版本不对,需要更新
|
2024-08-04 22:35:31 +08:00
|
|
|
|
{
|
|
|
|
|
if(first==-1)
|
|
|
|
|
{
|
|
|
|
|
first=rn->l2w_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last=rn->l2w_index;
|
|
|
|
|
|
2024-08-27 01:27:53 +08:00
|
|
|
|
rn->l2w_version=l2w_version;
|
2024-08-04 22:35:31 +08:00
|
|
|
|
|
|
|
|
|
rn_update_l2w_list.Add(rn);
|
|
|
|
|
|
|
|
|
|
++update_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++rn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(update_count>0)
|
|
|
|
|
{
|
2024-08-27 01:27:53 +08:00
|
|
|
|
assign_buffer->UpdateLocalToWorld(rn_update_l2w_list,first,last);
|
2024-08-04 22:35:31 +08:00
|
|
|
|
rn_update_l2w_list.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 03:36:01 +08:00
|
|
|
|
void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn)
|
|
|
|
|
{
|
|
|
|
|
if(!sn)return;
|
|
|
|
|
|
|
|
|
|
if(!assign_buffer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int node_count=rn_list.GetCount();
|
|
|
|
|
|
|
|
|
|
if(node_count<=0)return;
|
|
|
|
|
RenderNode *rn=rn_list.GetData();
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<node_count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(rn->scene_node==sn)
|
|
|
|
|
{
|
|
|
|
|
assign_buffer->UpdateMaterialInstance(rn);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++rn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
|
|
|
|
{
|
2024-05-27 01:42:10 +08:00
|
|
|
|
mi =ri->GetMaterialInstance();
|
2024-05-29 00:55:12 +08:00
|
|
|
|
pdb =ri->GetDataBuffer();
|
2024-05-27 01:42:10 +08:00
|
|
|
|
prd =ri->GetRenderData();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
void MaterialRenderList::ReallocICB()
|
|
|
|
|
{
|
|
|
|
|
const uint32_t icb_new_count=power_to_2(rn_list.GetCount());
|
|
|
|
|
|
|
|
|
|
if(icb_draw)
|
|
|
|
|
{
|
|
|
|
|
if(icb_new_count<=icb_draw->GetMaxCount())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
delete icb_draw;
|
|
|
|
|
icb_draw=nullptr;
|
|
|
|
|
|
|
|
|
|
delete icb_draw_indexed;
|
|
|
|
|
icb_draw_indexed=nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
icb_draw=device->CreateIndirectDrawBuffer(icb_new_count);
|
|
|
|
|
icb_draw_indexed=device->CreateIndirectDrawIndexedBuffer(icb_new_count);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 13:39:16 +08:00
|
|
|
|
void MaterialRenderList::WriteICB(VkDrawIndirectCommand *dicp,RenderItem *ri)
|
|
|
|
|
{
|
|
|
|
|
dicp->vertexCount =ri->prd->vertex_count;
|
|
|
|
|
dicp->instanceCount =ri->instance_count;
|
|
|
|
|
dicp->firstVertex =ri->prd->vertex_offset;
|
|
|
|
|
dicp->firstInstance =ri->first_instance;
|
|
|
|
|
}
|
2025-01-15 02:42:04 +08:00
|
|
|
|
|
2024-05-30 13:39:16 +08:00
|
|
|
|
void MaterialRenderList::WriteICB(VkDrawIndexedIndirectCommand *diicp,RenderItem *ri)
|
|
|
|
|
{
|
|
|
|
|
diicp->indexCount =ri->prd->index_count;
|
|
|
|
|
diicp->instanceCount=ri->instance_count;
|
|
|
|
|
diicp->firstIndex =ri->prd->first_index;
|
|
|
|
|
diicp->vertexOffset =ri->prd->vertex_offset;
|
|
|
|
|
diicp->firstInstance=ri->first_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
void MaterialRenderList::Stat()
|
|
|
|
|
{
|
|
|
|
|
const uint count=rn_list.GetCount();
|
|
|
|
|
RenderNode *rn=rn_list.GetData();
|
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
ReallocICB();
|
|
|
|
|
|
|
|
|
|
VkDrawIndirectCommand *dicp=icb_draw->MapCmd();
|
|
|
|
|
VkDrawIndexedIndirectCommand *diicp=icb_draw_indexed->MapCmd();
|
|
|
|
|
|
2023-09-05 10:28:03 +08:00
|
|
|
|
ri_array.Clear();
|
|
|
|
|
ri_array.Alloc(count);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2023-09-05 10:28:03 +08:00
|
|
|
|
RenderItem *ri=ri_array.GetData();
|
2024-08-02 23:17:07 +08:00
|
|
|
|
Renderable *ro=rn->scene_node->GetRenderable();
|
2023-09-20 15:55:14 +08:00
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
ri_count=1;
|
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
ri->first_instance=0;
|
2024-05-28 23:10:50 +08:00
|
|
|
|
ri->instance_count=1;
|
2024-08-02 23:17:07 +08:00
|
|
|
|
ri->Set(ro);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-28 23:49:28 +08:00
|
|
|
|
last_data_buffer=ri->pdb;
|
|
|
|
|
last_vdm =ri->pdb->vdm;
|
2024-05-27 01:42:10 +08:00
|
|
|
|
last_render_data=ri->prd;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
++rn;
|
|
|
|
|
|
|
|
|
|
for(uint i=1;i<count;i++)
|
2023-09-19 21:45:54 +08:00
|
|
|
|
{
|
2024-08-02 23:17:07 +08:00
|
|
|
|
ro=rn->scene_node->GetRenderable();
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
if(*last_data_buffer!=*ro->GetDataBuffer())
|
|
|
|
|
if(*last_render_data==*ro->GetRenderData())
|
|
|
|
|
{
|
|
|
|
|
++ri->instance_count;
|
|
|
|
|
++rn;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-05-30 13:14:13 +08:00
|
|
|
|
|
|
|
|
|
if(ri->pdb->vdm)
|
|
|
|
|
{
|
|
|
|
|
if(ri->pdb->ibo)
|
2024-05-30 13:39:16 +08:00
|
|
|
|
WriteICB(diicp,ri);
|
2024-05-29 00:55:12 +08:00
|
|
|
|
else
|
2024-05-30 13:39:16 +08:00
|
|
|
|
WriteICB(dicp,ri);
|
2024-05-30 13:14:13 +08:00
|
|
|
|
|
|
|
|
|
++dicp;
|
|
|
|
|
++diicp;
|
2024-05-29 00:55:12 +08:00
|
|
|
|
}
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
++ri_count;
|
|
|
|
|
++ri;
|
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
ri->first_instance=i;
|
2024-05-28 23:10:50 +08:00
|
|
|
|
ri->instance_count=1;
|
2024-08-02 23:17:07 +08:00
|
|
|
|
ri->Set(ro);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-29 00:55:12 +08:00
|
|
|
|
last_data_buffer=ri->pdb;
|
|
|
|
|
last_vdm =ri->pdb->vdm;
|
2024-05-27 01:42:10 +08:00
|
|
|
|
last_render_data=ri->prd;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
++rn;
|
|
|
|
|
}
|
2024-05-30 01:14:27 +08:00
|
|
|
|
|
2024-05-30 13:39:16 +08:00
|
|
|
|
if(ri->pdb->vdm)
|
|
|
|
|
{
|
|
|
|
|
if(ri->pdb->ibo)
|
|
|
|
|
WriteICB(diicp,ri);
|
|
|
|
|
else
|
|
|
|
|
WriteICB(dicp,ri);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
icb_draw->Unmap();
|
|
|
|
|
icb_draw_indexed->Unmap();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
bool MaterialRenderList::BindVAB(const PrimitiveDataBuffer *pdb,const uint ri_index)
|
2023-06-01 15:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
|
|
|
|
|
2023-10-12 02:24:58 +08:00
|
|
|
|
//const VIL *vil=last_vil;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-27 01:42:10 +08:00
|
|
|
|
//if(vil->GetCount(VertexInputGroup::Basic)!=prb->vab_count)
|
2023-10-12 02:24:58 +08:00
|
|
|
|
// return(false); //这里基本不太可能,因为CreateRenderable时就会检查值是否一样
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
vab_list->Restart();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-04-24 01:44:01 +08:00
|
|
|
|
//Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来
|
2023-06-01 15:08:45 +08:00
|
|
|
|
{
|
2024-05-28 23:10:50 +08:00
|
|
|
|
vab_list->Add(pdb->vab_list,
|
2024-06-02 15:27:03 +08:00
|
|
|
|
pdb->vab_offset,
|
2024-05-28 23:10:50 +08:00
|
|
|
|
pdb->vab_count);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 17:58:39 +08:00
|
|
|
|
if(assign_buffer) //L2W/MI分发组
|
2024-05-28 23:10:50 +08:00
|
|
|
|
vab_list->Add(assign_buffer->GetVAB(),0);//ASSIGN_VAB_STRIDE_BYTES*ri_index);
|
2024-03-26 01:20:20 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
//if(!vab_list.IsFull()) //Joint组,暂未支持
|
2023-09-05 20:19:53 +08:00
|
|
|
|
//{
|
|
|
|
|
// const uint joint_id_binding_count=vil->GetCount(VertexInputGroup::JointID);
|
|
|
|
|
|
|
|
|
|
// if(joint_id_binding_count>0) //有矩阵信息
|
|
|
|
|
// {
|
|
|
|
|
// count+=joint_id_binding_count;
|
|
|
|
|
|
2024-05-25 22:08:01 +08:00
|
|
|
|
// if(count<vab_count) //JointWeight组
|
2023-09-05 20:19:53 +08:00
|
|
|
|
// {
|
|
|
|
|
// const uint joing_weight_binding_count=vil->GetCount(VertexInputGroup::JointWeight);
|
|
|
|
|
|
|
|
|
|
// if(joing_weight_binding_count!=1)
|
|
|
|
|
// {
|
|
|
|
|
// ++count;
|
|
|
|
|
// }
|
|
|
|
|
// else //JointWieght不为1是个bug,除非未来支持8权重
|
|
|
|
|
// {
|
|
|
|
|
// return(false);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else //有JointID没有JointWeight? 这是个BUG
|
|
|
|
|
// {
|
|
|
|
|
// return(false);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
2024-05-25 22:08:01 +08:00
|
|
|
|
//if(count!=vab_count)
|
2023-09-05 20:19:53 +08:00
|
|
|
|
//{
|
|
|
|
|
// //还有没支持的绑定组????
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2023-09-05 20:19:53 +08:00
|
|
|
|
// return(false);
|
|
|
|
|
//}
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
cmd_buf->BindVAB(vab_list);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 13:39:16 +08:00
|
|
|
|
void MaterialRenderList::ProcIndirectRender()
|
|
|
|
|
{
|
|
|
|
|
if(last_data_buffer->ibo)
|
|
|
|
|
icb_draw_indexed->DrawIndexed(*cmd_buf,first_indirect_draw_index,indirect_draw_count);
|
|
|
|
|
else
|
|
|
|
|
icb_draw->Draw(*cmd_buf,first_indirect_draw_index,indirect_draw_count);
|
|
|
|
|
|
|
|
|
|
first_indirect_draw_index=-1;
|
|
|
|
|
indirect_draw_count=0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
void MaterialRenderList::Render(RenderItem *ri)
|
|
|
|
|
{
|
2025-01-15 02:42:04 +08:00
|
|
|
|
if(*(ri->pdb)!=*last_data_buffer) //换buf了
|
2023-06-01 15:08:45 +08:00
|
|
|
|
{
|
2024-05-30 13:39:16 +08:00
|
|
|
|
if(indirect_draw_count) //如果有间接绘制的数据,赶紧给画了
|
|
|
|
|
ProcIndirectRender();
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
last_data_buffer=ri->pdb;
|
2024-05-27 01:42:10 +08:00
|
|
|
|
last_render_data=nullptr;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
BindVAB(ri->pdb,ri->first_instance);
|
2024-05-28 02:21:33 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
if(ri->pdb->ibo)
|
2025-01-15 02:42:04 +08:00
|
|
|
|
cmd_buf->BindIBO(ri->pdb->ibo);
|
2024-05-25 22:08:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 23:07:05 +08:00
|
|
|
|
if(ri->pdb->vdm)
|
2024-05-30 13:39:16 +08:00
|
|
|
|
{
|
|
|
|
|
if(indirect_draw_count==0)
|
|
|
|
|
first_indirect_draw_index=ri->first_instance;
|
|
|
|
|
|
|
|
|
|
++indirect_draw_count;
|
|
|
|
|
}
|
2024-05-31 23:07:05 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->Draw(ri->pdb,ri->prd,ri->instance_count,ri->first_instance);
|
|
|
|
|
}
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialRenderList::Render(RenderCmdBuffer *rcb)
|
|
|
|
|
{
|
|
|
|
|
if(!rcb)return;
|
|
|
|
|
const uint count=rn_list.GetCount();
|
|
|
|
|
|
|
|
|
|
if(count<=0)return;
|
|
|
|
|
|
|
|
|
|
if(ri_count<=0)return;
|
|
|
|
|
|
|
|
|
|
cmd_buf=rcb;
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
cmd_buf->BindPipeline(rp_index.pipeline);
|
|
|
|
|
|
2024-05-28 23:49:28 +08:00
|
|
|
|
last_data_buffer=nullptr;
|
|
|
|
|
last_vdm =nullptr;
|
|
|
|
|
last_render_data=nullptr;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-25 17:58:39 +08:00
|
|
|
|
if(assign_buffer)
|
2025-01-15 02:42:04 +08:00
|
|
|
|
assign_buffer->Bind(rp_index.material);
|
2023-10-12 02:24:58 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
cmd_buf->BindDescriptorSets(rp_index.material);
|
2023-10-12 02:24:58 +08:00
|
|
|
|
|
2024-05-29 00:55:12 +08:00
|
|
|
|
RenderItem *ri=ri_array.GetData();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
for(uint i=0;i<ri_count;i++)
|
|
|
|
|
{
|
|
|
|
|
Render(ri);
|
|
|
|
|
++ri;
|
|
|
|
|
}
|
2024-05-30 13:39:16 +08:00
|
|
|
|
|
|
|
|
|
if(indirect_draw_count) //如果有间接绘制的数据,赶紧给画了
|
|
|
|
|
ProcIndirectRender();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
VK_NAMESPACE_END
|