create DrawData that it split from VertexInputData

This commit is contained in:
2024-05-25 22:08:01 +08:00
parent a5e76988c7
commit 6740764f07
20 changed files with 225 additions and 140 deletions

View File

@@ -130,13 +130,13 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
return(true);
}
//void RenderCmdBuffer::BindIBO(const IBAccess *iba)
//{
// vkCmdBindIndexBuffer( cmd_buf,
// iba->buffer->GetBuffer(),
// iba->start,
// VkIndexType(iba->buffer->GetType()));
//}
void RenderCmdBuffer::BindIBO(IndexBuffer *ibo,VkDeviceSize offset)
{
vkCmdBindIndexBuffer(cmd_buf,
ibo->GetBuffer(),
offset*ibo->GetStride(),
VkIndexType(ibo->GetType()));
}
bool RenderCmdBuffer::BindVBO(Renderable *ri)
{
@@ -145,18 +145,18 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
const VertexInputData *vid=ri->GetVertexInputData();
if(vid->binding_count<=0)
if(vid->vab_count<=0)
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)
vkCmdBindIndexBuffer(cmd_buf,
indices_buffer->GetBuffer(),
vid->ib_access->start,
VkIndexType(indices_buffer->GetType()));
vkCmdBindVertexBuffers(cmd_buf,0,vid->vab_count,vid->vab_list,dd->vab_offset);
if(vid->ibo&&dd->index_count)
BindIBO(vid->ibo,dd->index_start);
return(true);
}
@@ -185,23 +185,31 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer,
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)
DrawIndexed(vid->ib_access->count);
if(!vid||!dd)
return;
if (vid->ibo)
DrawIndexed(dd->index_count);
else
Draw(vid->vertex_count);
Draw(dd->vertex_count);
}
void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count)
{
if(!iba||instance_count<=0)return;
vkCmdBindIndexBuffer(cmd_buf,
iba->buffer->GetBuffer(),
iba->start*iba->buffer->GetStride(),
VkIndexType(iba->buffer->GetType()));
vkCmdDrawIndexed(cmd_buf,iba->count,instance_count,0,0,0);
}
//void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count)
//{
// if(!iba||instance_count<=0)return;
//
// vkCmdBindIndexBuffer(cmd_buf,
// iba->buffer->GetBuffer(),
// iba->start*iba->buffer->GetStride(),
// VkIndexType(iba->buffer->GetType()));
//
// vkCmdDrawIndexed(cmd_buf,
// iba->count,
// instance_count,
// 0, //first index
// 0, //vertex offset
// 0); //first instance
//}
VK_NAMESPACE_END

View File

@@ -69,7 +69,7 @@ namespace
void DescriptorSet::Clear()
{
buffer_list.Clear();
vab_list.Clear();
image_list.Clear();
wds_list.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);
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;
@@ -137,7 +137,7 @@ bool DescriptorSet::BindSSBO(const int binding,const DeviceBuffer *buf,const VkD
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;

View File

@@ -18,9 +18,9 @@ namespace
{
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);
DescriptorSetAllocateInfo alloc_info;
@@ -34,7 +34,7 @@ namespace
if(vkAllocateDescriptorSets(device,&alloc_info,&desc_set)!=VK_SUCCESS)
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

View File

@@ -13,7 +13,7 @@ Material::Material(const AnsiString &n)
{
name=n;
vertex_input=nullptr;
vertex_input_data=nullptr;
shader_maps=new ShaderModuleMap;
desc_manager=nullptr;
pipeline_layout_data=nullptr;
@@ -28,7 +28,7 @@ Material::~Material()
{
SAFE_CLEAR(mi_data_manager);
ReleaseVertexInput(vertex_input);
ReleaseVertexInput(vertex_input_data);
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 vertex_input->GetDefaultVIL();
return vertex_input_data->GetDefaultVIL();
}
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)
{
return vertex_input->Release(vil);
return vertex_input_data->Release(vil);
}
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)

View File

@@ -26,7 +26,7 @@ PipelineLayoutData *GPUDevice::CreatePipelineLayoutData(const MaterialDescriptor
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_count;

View File

@@ -9,7 +9,7 @@ struct PipelineLayoutData
{
VkDevice device;
int binding_count[DESCRIPTOR_SET_TYPE_COUNT];
int vab_count[DESCRIPTOR_SET_TYPE_COUNT];
VkDescriptorSetLayout layouts[DESCRIPTOR_SET_TYPE_COUNT];
VkDescriptorSetLayout fin_dsl[DESCRIPTOR_SET_TYPE_COUNT];

View File

@@ -61,4 +61,9 @@ IBAccess *Primitive::GetIBAccess()
return prim_data->GetIBAccess();
}
IndexBuffer *Primitive::GetIBO()
{
return prim_data->GetIBO();
}
VK_NAMESPACE_END

View File

@@ -38,7 +38,9 @@ public:
const int GetVABIndex (const AnsiString &name)const;
VABAccess * GetVABAccess (const int index);
VABAccess * GetVABAccess (const AnsiString &name);
IBAccess * GetIBAccess (){return &ib_access;}
IndexBuffer * GetIBO (){return ib_access.buffer;}
public:

View File

@@ -124,7 +124,7 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
ShaderCreateInfoVertex *vert=mci->GetVS();
if(vert)
mtl->vertex_input=GetVertexInput(vert->sdm->GetShaderStageIO().input);
mtl->vertex_input_data=GetVertexInput(vert->sdm->GetShaderStageIO().input);
}
{

View File

@@ -3,46 +3,92 @@
#include<hgl/graph/VKMaterialParameters.h>
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
#include<hgl/graph/VKIndexBuffer.h>
#include<hgl/log/LogInfo.h>
VK_NAMESPACE_BEGIN
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];
buffer_offset=new VkDeviceSize[binding_count];
vab_list=hgl_zero_new<VkBuffer>(vab_count);
vertex_count=vc;
if(!iba||!iba->buffer)
ib_access=nullptr;
if(iba&&iba->buffer)
ibo=iba->buffer;
else
ib_access=iba;
ibo=nullptr;
}
VertexInputData::~VertexInputData()
{
delete[] buffer_list;
delete[] buffer_offset;
delete[] vab_list;
}
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;
pipeline=p;
mat_inst=mi;
vertex_input=vi;
vertex_input_data=vid;
draw_data=dd;
}
DrawData::DrawData(const uint32_t bc,const VkDeviceSize vc,const IBAccess *iba)
{
vab_count=bc;
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::~Renderable()
{
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
delete vertex_input;
}
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
{
if(!prim||!mi||!p)return(nullptr);
@@ -58,7 +104,10 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
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);
VABAccess *vab_access;
@@ -96,11 +145,11 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
return(nullptr);
}
vid->buffer_offset[i]=vab_access->start*vif->stride;
vid->buffer_list[i]=vab_access->vab->GetBuffer();
dd->vab_offset[i]=vab_access->start*vif->stride;
vid->vab_list[i]=vab_access->vab->GetBuffer();
++vif;
}
return(new Renderable(prim,mi,p,vid));
return(new Renderable(prim,mi,p,vid,dd));
}
VK_NAMESPACE_END