[WIP] optimizing VDM Support
This commit is contained in:
parent
742fe201ad
commit
86ff7517d9
@ -216,7 +216,7 @@ public:
|
|||||||
{
|
{
|
||||||
if(!ri)return(false);
|
if(!ri)return(false);
|
||||||
|
|
||||||
const PrimitiveRenderBuffer *prb=ri->GetRenderBuffer();
|
const PrimitiveDataBuffer *prb=ri->GetRenderBuffer();
|
||||||
|
|
||||||
cb->Begin();
|
cb->Begin();
|
||||||
cb->BindFramebuffer(rp,fb);
|
cb->BindFramebuffer(rp,fb);
|
||||||
|
@ -28,7 +28,7 @@ private:
|
|||||||
|
|
||||||
Pipeline * pipeline;
|
Pipeline * pipeline;
|
||||||
MaterialInstance * mi;
|
MaterialInstance * mi;
|
||||||
const PrimitiveRenderBuffer * prb;
|
const PrimitiveDataBuffer * prb;
|
||||||
const PrimitiveRenderData * prd;
|
const PrimitiveRenderData * prd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -46,10 +46,10 @@ protected:
|
|||||||
VABList * vbo_list;
|
VABList * vbo_list;
|
||||||
|
|
||||||
Pipeline * last_pipeline;
|
Pipeline * last_pipeline;
|
||||||
const PrimitiveRenderBuffer * last_render_buf;
|
const PrimitiveDataBuffer * last_render_buf;
|
||||||
const PrimitiveRenderData * last_render_data;
|
const PrimitiveRenderData * last_render_data;
|
||||||
|
|
||||||
bool BindVAB(const PrimitiveRenderBuffer *,const PrimitiveRenderData *,const uint);
|
bool BindVAB(const PrimitiveDataBuffer *,const uint);
|
||||||
|
|
||||||
void Render(RenderItem *);
|
void Render(RenderItem *);
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ protected:
|
|||||||
|
|
||||||
uint32_t index_number; ///<索引数量
|
uint32_t index_number; ///<索引数量
|
||||||
IndexType index_type; ///<索引类型
|
IndexType index_type; ///<索引类型
|
||||||
IBAccess * iba; ///<索引缓冲区
|
IndexBuffer * ibo; ///<索引缓冲区
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -52,11 +52,12 @@ public: //顶点缓冲区
|
|||||||
|
|
||||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||||
|
|
||||||
VABAccess * AcquireVAB (const AnsiString &name,const VkFormat &format,const void *data=nullptr); ///<请求一个顶点属性数据区
|
const int GetVABIndex (const AnsiString &name,const VkFormat &format); ///<取得顶点属性索引
|
||||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data) ///<直接写入顶点属性数据
|
|
||||||
{
|
void * MapVAB (const int vab_index); ///<映射一个顶点属性数据区
|
||||||
return AcquireVAB(name,format,data);
|
void UnmapVAB (const int vab_index); ///<取消映射
|
||||||
}
|
|
||||||
|
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data); ///<直接写入顶点属性数据
|
||||||
|
|
||||||
public: //索引缓冲区
|
public: //索引缓冲区
|
||||||
|
|
||||||
@ -81,28 +82,27 @@ public: //创建可渲染对象
|
|||||||
*/
|
*/
|
||||||
template<typename T> class VABRawMap
|
template<typename T> class VABRawMap
|
||||||
{
|
{
|
||||||
VABAccess *vaba;
|
PrimitiveCreater *pc;
|
||||||
|
int vab_index;
|
||||||
T *map_ptr;
|
T *map_ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
|
VABRawMap(PrimitiveCreater *c,const VkFormat &format,const AnsiString &name)
|
||||||
{
|
{
|
||||||
vaba=pc->AcquireVAB(name,format);
|
pc=c;
|
||||||
|
vab_index=pc->GetVABIndex(name,format);
|
||||||
if(vaba)
|
|
||||||
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
map_ptr=(T *)(pc->MapVAB(vab_index));
|
||||||
else
|
|
||||||
map_ptr=nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~VABRawMap()
|
~VABRawMap()
|
||||||
{
|
{
|
||||||
if(vaba)
|
if(map_ptr)
|
||||||
vaba->vab->Unmap();
|
pc->UnmapVAB(vab_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool IsValid()const{ return vaba; }
|
const bool IsValid()const{ return map_ptr; }
|
||||||
|
|
||||||
operator T *(){ return map_ptr; }
|
operator T *(){ return map_ptr; }
|
||||||
};//template<typename T> class VABRawMap
|
};//template<typename T> class VABRawMap
|
||||||
@ -121,19 +121,21 @@ typedef VABRawMap<double> VABRawMapDouble;
|
|||||||
*/
|
*/
|
||||||
template<typename T> class VABMap
|
template<typename T> class VABMap
|
||||||
{
|
{
|
||||||
VABAccess *vaba;
|
PrimitiveCreater *pc;
|
||||||
|
int vab_index;
|
||||||
T *vb;
|
T *vb;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||||
{
|
{
|
||||||
vaba=pc->AcquireVAB(name,T::GetVulkanFormat(),nullptr);
|
pc=c;
|
||||||
|
vab_index=pc->GetVABIndex(name,T::GetVulkanFormat(),nullptr);
|
||||||
|
|
||||||
if(vaba)
|
void *map_ptr=(T *)(pc->MapVAB(vab_index));
|
||||||
|
|
||||||
|
if(map_ptr)
|
||||||
{
|
{
|
||||||
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
|
|
||||||
|
|
||||||
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
||||||
|
|
||||||
vb->Begin();
|
vb->Begin();
|
||||||
@ -146,8 +148,8 @@ public:
|
|||||||
|
|
||||||
~VABMap()
|
~VABMap()
|
||||||
{
|
{
|
||||||
if(vaba)
|
if(vab)
|
||||||
vaba->vab->Unmap();
|
pc->UnmapVAB(vab_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Restart()
|
void Restart()
|
||||||
|
@ -54,34 +54,14 @@ class DeviceMemory;
|
|||||||
class DeviceBuffer;
|
class DeviceBuffer;
|
||||||
struct DeviceBufferData;
|
struct DeviceBufferData;
|
||||||
|
|
||||||
struct PrimitiveRenderBuffer;
|
struct PrimitiveDataBuffer;
|
||||||
struct PrimitiveRenderData;
|
struct PrimitiveRenderData;
|
||||||
|
|
||||||
class VertexAttribBuffer;
|
class VertexAttribBuffer;
|
||||||
using VAB=VertexAttribBuffer;
|
using VAB=VertexAttribBuffer;
|
||||||
|
|
||||||
struct VABAccess
|
|
||||||
{
|
|
||||||
VAB *vab;
|
|
||||||
uint32_t start;
|
|
||||||
uint32_t count;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CompOperatorMemcmp(const VABAccess &);
|
|
||||||
};//class VABAccess
|
|
||||||
|
|
||||||
class IndexBuffer;
|
class IndexBuffer;
|
||||||
|
|
||||||
struct IndexBufferAccess
|
|
||||||
{
|
|
||||||
IndexBuffer *buffer;
|
|
||||||
uint32_t start;
|
|
||||||
uint32_t count;
|
|
||||||
};
|
|
||||||
|
|
||||||
using IBAccess=IndexBufferAccess;
|
|
||||||
|
|
||||||
class GPUCmdBuffer;
|
class GPUCmdBuffer;
|
||||||
class RenderCmdBuffer;
|
class RenderCmdBuffer;
|
||||||
class TextureCmdBuffer;
|
class TextureCmdBuffer;
|
||||||
|
@ -165,12 +165,16 @@ public:
|
|||||||
|
|
||||||
if(!vab_list->IsFull())return(false);
|
if(!vab_list->IsFull())return(false);
|
||||||
|
|
||||||
vkCmdBindVertexBuffers(cmd_buf,0,vab_list->vab_count,vab_list->vab_list,vab_list->vab_offset);
|
vkCmdBindVertexBuffers(cmd_buf,
|
||||||
|
0, //first binding
|
||||||
|
vab_list->vab_count, //binding count
|
||||||
|
vab_list->vab_list, //buffers
|
||||||
|
vab_list->vab_offset); //buffer offsets
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindIBO(IndexBuffer *ibo,VkDeviceSize offset); ///<绑定IBO,注意offset意为索引偏移量,不是字节
|
void BindIBO(IBAccess *);
|
||||||
|
|
||||||
bool BindVAB(Renderable *);
|
bool BindVAB(Renderable *);
|
||||||
|
|
||||||
@ -209,7 +213,7 @@ 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 PrimitiveRenderBuffer *prb,const PrimitiveRenderData *prd);
|
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd);
|
||||||
// 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
|
||||||
|
@ -22,7 +22,7 @@ class Material
|
|||||||
{
|
{
|
||||||
AnsiString name;
|
AnsiString name;
|
||||||
|
|
||||||
VertexInput *primitive_render_buffer;
|
VertexInput *vertex_input;
|
||||||
|
|
||||||
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 primitive_render_buffer;}
|
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
||||||
|
|
||||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||||
|
|
||||||
|
@ -7,18 +7,8 @@
|
|||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
/**
|
/**
|
||||||
* 单一图元数据访问接口<br>
|
* 原始图元数据访问接口<br>
|
||||||
*
|
* Primitive的存为是为了屏蔽PrimitiveData的初始化之类的访问接口,以便于更好的管理和使用
|
||||||
* 这个只是单纯的提供原始VAB/IB数据,派生为两类
|
|
||||||
*
|
|
||||||
* 一类是传统的,使用独统的独立VAB的
|
|
||||||
* 一类是使用VDM的
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* WIP: *** 1.将数据全部转移到PrimitiveData,完成旧的渲染测试
|
|
||||||
* 2.改成抽象类,将独立VAB的做成一个实现
|
|
||||||
* 3.实现VDM支持
|
|
||||||
*/
|
*/
|
||||||
class Primitive
|
class Primitive
|
||||||
{
|
{
|
||||||
@ -43,9 +33,9 @@ public:
|
|||||||
|
|
||||||
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 ();
|
|
||||||
IndexBuffer * GetIBO ();
|
IndexBuffer * GetIBO ();
|
||||||
|
|
||||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||||
|
@ -9,32 +9,50 @@
|
|||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
#include<hgl/graph/VertexAttrib.h>
|
#include<hgl/graph/VertexAttrib.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
struct PrimitiveRenderBuffer
|
/**
|
||||||
|
* 原始图元数据缓冲区<Br>
|
||||||
|
* 提供在渲染之前的数据绑定信息
|
||||||
|
*/
|
||||||
|
struct PrimitiveDataBuffer
|
||||||
{
|
{
|
||||||
uint32_t vab_count;
|
uint32_t vab_count;
|
||||||
VkBuffer * vab_list;
|
VkBuffer * vab_list;
|
||||||
|
|
||||||
|
// 理论上讲,每个VAB绑定时都是可以指定byte offsets的。但是随后Draw时,又可以指定vertexOffset。
|
||||||
|
// 在我们支持的两种draw模式中,一种是每个模型一批VAB,所有VAB的offset都是0。
|
||||||
|
// 另一种是使用VDM,为了批量渲染,所有的VAB又必须对齐,所以每个VAB单独指定offset也不可行。
|
||||||
|
// 所以干脆不支持VAB的offset,只支持vertexOffset。
|
||||||
|
|
||||||
|
// uint32_t * vab_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移
|
||||||
|
|
||||||
|
// IndexBuffer 同理也不再支持buffer的offset
|
||||||
|
|
||||||
IndexBuffer * ibo;
|
IndexBuffer * ibo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PrimitiveRenderBuffer(const uint32_t,const uint32_t,const IBAccess *iba);
|
PrimitiveDataBuffer(const uint32_t,const uint32_t, IndexBuffer *);
|
||||||
~PrimitiveRenderBuffer();
|
~PrimitiveDataBuffer();
|
||||||
|
|
||||||
const bool Comp(const PrimitiveRenderBuffer *prb)const;
|
const bool Comp(const PrimitiveDataBuffer *prb)const;
|
||||||
};//struct PrimitiveRenderBuffer
|
};//struct PrimitiveDataBuffer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原始图元渲染数据<Br>
|
||||||
|
* 提供在渲染时的数据
|
||||||
|
*/
|
||||||
struct PrimitiveRenderData
|
struct PrimitiveRenderData
|
||||||
{
|
{
|
||||||
uint vab_count;
|
uint vab_count;
|
||||||
VkDeviceSize * vab_offset;
|
|
||||||
uint32_t vertex_count;
|
uint32_t vertex_count;
|
||||||
|
|
||||||
uint32_t index_start;
|
|
||||||
uint32_t index_count;
|
uint32_t index_count;
|
||||||
|
|
||||||
|
int32_t vertex_offset; //注意:这里的offset是相对于vertex的,代表第几个顶点,不是字节偏移
|
||||||
|
uint32_t first_index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PrimitiveRenderData(const uint32_t bc,const uint32_t vc,const IBAccess *iba);
|
PrimitiveRenderData(const uint32_t bc,const uint32_t vc);
|
||||||
~PrimitiveRenderData();
|
~PrimitiveRenderData();
|
||||||
|
|
||||||
const bool Comp(const PrimitiveRenderData *)const;
|
const bool Comp(const PrimitiveRenderData *)const;
|
||||||
@ -49,14 +67,14 @@ class Renderable
|
|||||||
MaterialInstance * mat_inst;
|
MaterialInstance * mat_inst;
|
||||||
Primitive * primitive;
|
Primitive * primitive;
|
||||||
|
|
||||||
PrimitiveRenderBuffer * primitive_render_buffer;
|
PrimitiveDataBuffer * primitive_data_buffer;
|
||||||
PrimitiveRenderData * primitive_render_data;
|
PrimitiveRenderData * primitive_render_data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||||
|
|
||||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveRenderBuffer *,PrimitiveRenderData *);
|
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveDataBuffer *,PrimitiveRenderData *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -64,7 +82,7 @@ public:
|
|||||||
{
|
{
|
||||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||||
|
|
||||||
SAFE_CLEAR(primitive_render_buffer);
|
SAFE_CLEAR(primitive_data_buffer);
|
||||||
SAFE_CLEAR(primitive_render_data);
|
SAFE_CLEAR(primitive_render_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +95,7 @@ public:
|
|||||||
Primitive * GetPrimitive (){return primitive;}
|
Primitive * GetPrimitive (){return primitive;}
|
||||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||||
|
|
||||||
const PrimitiveRenderBuffer * GetRenderBuffer ()const{return primitive_render_buffer;}
|
const PrimitiveDataBuffer * GetRenderBuffer ()const{return primitive_data_buffer;}
|
||||||
const PrimitiveRenderData * GetRenderData ()const{return primitive_render_data;}
|
const PrimitiveRenderData * GetRenderData ()const{return primitive_render_data;}
|
||||||
};//class Renderable
|
};//class Renderable
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ void MaterialRenderList::Stat()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialRenderList::BindVAB(const PrimitiveRenderBuffer *prb,const PrimitiveRenderData *prd,const uint ri_index)
|
bool MaterialRenderList::BindVAB(const PrimitiveDataBuffer *prb,const uint ri_index)
|
||||||
{
|
{
|
||||||
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
//binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ bool MaterialRenderList::BindVAB(const PrimitiveRenderBuffer *prb,const Primitiv
|
|||||||
//Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来
|
//Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来
|
||||||
{
|
{
|
||||||
vbo_list->Add(prb->vab_list,
|
vbo_list->Add(prb->vab_list,
|
||||||
nullptr,//prd->vab_offset, //暂时不用dd->vab_offset,全部写0,测试一下是否可以使用Draw时的firstVertex或vertexOffset
|
prb->vab_offset,
|
||||||
prb->vab_count);
|
prb->vab_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,16 +223,18 @@ void MaterialRenderList::Render(RenderItem *ri)
|
|||||||
last_render_buf=ri->prb;
|
last_render_buf=ri->prb;
|
||||||
last_render_data=nullptr;
|
last_render_data=nullptr;
|
||||||
|
|
||||||
BindVAB(ri->prb,ri->prd,ri->first);
|
BindVAB(ri->prb,ri->first);
|
||||||
cmd_buf->BindIBO(ri->prb->ibo,0);
|
|
||||||
|
if(ri->prb->ib_access->buffer)
|
||||||
|
cmd_buf->BindIBO(ri->prb->ib_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(last_render_buf->ibo)
|
if(last_render_buf->ib_access->buffer)
|
||||||
{
|
{
|
||||||
cmd_buf->DrawIndexed(ri->prd->index_count,
|
cmd_buf->DrawIndexed(ri->prd->index_count,
|
||||||
ri->count,
|
ri->count,
|
||||||
ri->prd->index_start,
|
ri->prd->first_index,
|
||||||
ri->prd->vab_offset[0], //因为vkCmdDrawIndexed的vertexOffset是针对所有VAB的,所以所有的VAB数据都必须是对齐的,
|
ri->prd->vertex_offset, //因为vkCmdDrawIndexed的vertexOffset是针对所有VAB的,所以所有的VAB数据都必须是对齐的,
|
||||||
//最终这里使用vab_offset[0]是可以的,因为它也等于其它所有的vab_offset。未来考虑统一成一个。
|
//最终这里使用vab_offset[0]是可以的,因为它也等于其它所有的vab_offset。未来考虑统一成一个。
|
||||||
ri->first); //这里vkCmdDrawIndexed的firstInstance参数指的是instance Rate更新的VAB的起始实例数,不是指instance批量渲染。
|
ri->first); //这里vkCmdDrawIndexed的firstInstance参数指的是instance Rate更新的VAB的起始实例数,不是指instance批量渲染。
|
||||||
//所以这里使用ri->first是对的。
|
//所以这里使用ri->first是对的。
|
||||||
|
@ -39,7 +39,7 @@ void PrimitiveCreater::Clear()
|
|||||||
|
|
||||||
index_number =0;
|
index_number =0;
|
||||||
index_type =IndexType::ERR;
|
index_type =IndexType::ERR;
|
||||||
iba =nullptr;
|
ibo =nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,const uint32_t index_count,IndexType it)
|
bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,const uint32_t index_count,IndexType it)
|
||||||
@ -84,9 +84,9 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
|||||||
|
|
||||||
if(index_number>0)
|
if(index_number>0)
|
||||||
{
|
{
|
||||||
iba=prim_data->InitIBO(index_number,index_type);
|
ibo=prim_data->InitIBO(index_number,index_type);
|
||||||
|
|
||||||
if(!iba)
|
if(!ibo)
|
||||||
{
|
{
|
||||||
delete prim_data;
|
delete prim_data;
|
||||||
return(false);
|
return(false);
|
||||||
@ -99,8 +99,8 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
|||||||
|
|
||||||
if(du)
|
if(du)
|
||||||
{
|
{
|
||||||
du->SetBuffer( iba->buffer->GetBuffer(), prim_name+":IndexBuffer:Buffer");
|
du->SetBuffer( ibo->GetBuffer(), prim_name+":IndexBuffer:Buffer");
|
||||||
du->SetDeviceMemory(iba->buffer->GetVkMemory(), prim_name+":IndexBuffer:Memory");
|
du->SetDeviceMemory(ibo->GetVkMemory(), prim_name+":IndexBuffer:Memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
@ -111,44 +111,83 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
VABAccess *PrimitiveCreater::AcquireVAB(const AnsiString &name,const VkFormat &acquire_format,const void *data)
|
const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &acquire_format)
|
||||||
{
|
{
|
||||||
if(!prim_data)return(nullptr);
|
if(!prim_data)return(-1);
|
||||||
if(name.IsEmpty())return(nullptr);
|
|
||||||
|
|
||||||
VABAccess *vab_access=prim_data->InitVAB(name,acquire_format,data);
|
const int vab_index=prim_data->GetVABIndex(name);
|
||||||
|
|
||||||
if(!vab_access)
|
VAB *vab=prim_data->GetVAB(vab_index);
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
if(!vab)
|
||||||
if(!vdm&&vab_access->vab)
|
return(-1);
|
||||||
{
|
|
||||||
|
vab=prim_data->InitVAB(vab_index,acquire_format,nullptr);
|
||||||
|
|
||||||
|
if(!vab)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
if (!vdm)
|
||||||
|
{
|
||||||
DebugUtils *du=device->GetDebugUtils();
|
DebugUtils *du=device->GetDebugUtils();
|
||||||
|
|
||||||
if(du)
|
if (du)
|
||||||
{
|
{
|
||||||
du->SetBuffer( vab_access->vab->GetBuffer(), prim_name+":VAB:Buffer:"+name);
|
du->SetBuffer(vab->GetBuffer(), prim_name+":VAB:Buffer:"+name);
|
||||||
du->SetDeviceMemory(vab_access->vab->GetVkMemory(), prim_name+":VAB:Memory:"+name);
|
du->SetDeviceMemory(vab->GetVkMemory(), prim_name+":VAB:Memory:"+name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
|
|
||||||
return vab_access;
|
return(vab_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *PrimitiveCreater::MapVAB(const int vab_index)
|
||||||
|
{
|
||||||
|
VAB *vab=prim_data->GetVAB(vab_index);
|
||||||
|
|
||||||
|
if(!vab)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
return vab->Map(prim_data->GetVertexOffset(),vertices_number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimitiveCreater::UnmapVAB(const int vab_index)
|
||||||
|
{
|
||||||
|
VAB *vab=prim_data->GetVAB(vab_index);
|
||||||
|
|
||||||
|
if(!vab)return;
|
||||||
|
|
||||||
|
vab->Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat &format, const void *data)
|
||||||
|
{
|
||||||
|
if(!prim_data)return(false);
|
||||||
|
|
||||||
|
const int vab_index=GetVABIndex(name,format);
|
||||||
|
|
||||||
|
VAB *vab=prim_data->GetVAB(vab_index);
|
||||||
|
|
||||||
|
if(!vab)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return vab->Write(data,prim_data->GetVertexOffset(),vertices_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *PrimitiveCreater::MapIBO()
|
void *PrimitiveCreater::MapIBO()
|
||||||
{
|
{
|
||||||
if(!prim_data)return(nullptr);
|
if(!prim_data)return(nullptr);
|
||||||
if(!iba)return(nullptr);
|
if(!ibo)return(nullptr);
|
||||||
|
|
||||||
return iba->buffer->Map(iba->start,iba->count);
|
return ibo->Map(prim_data->GetFirstIndex(),index_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitiveCreater::UnmapIBO()
|
void PrimitiveCreater::UnmapIBO()
|
||||||
{
|
{
|
||||||
if(iba)
|
if(ibo)
|
||||||
iba->buffer->Unmap();
|
ibo->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrimitiveCreater::WriteIBO(const void *data,const uint32_t count)
|
bool PrimitiveCreater::WriteIBO(const void *data,const uint32_t count)
|
||||||
@ -156,12 +195,12 @@ bool PrimitiveCreater::WriteIBO(const void *data,const uint32_t count)
|
|||||||
if(!data)return(false);
|
if(!data)return(false);
|
||||||
if(!prim_data)return(false);
|
if(!prim_data)return(false);
|
||||||
|
|
||||||
IBAccess *iba=prim_data->GetIBAccess();
|
IndexBuffer *ibo=prim_data->GetIBO();
|
||||||
|
|
||||||
if(count>0&&count>index_number)
|
if(count>0&&count>index_number)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
return iba->buffer->Write(data,iba->start,count);
|
return ibo->Write(data,prim_data->GetFirstIndex(),count);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *PrimitiveCreater::Create()
|
Primitive *PrimitiveCreater::Create()
|
||||||
|
@ -130,11 +130,17 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
|
|||||||
return(true);
|
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,
|
vkCmdBindIndexBuffer(cmd_buf,
|
||||||
ibo->GetBuffer(),
|
ibo->GetBuffer(),
|
||||||
offset*ibo->GetStride(),
|
iba->start*ibo->GetStride(),
|
||||||
VkIndexType(ibo->GetType()));
|
VkIndexType(ibo->GetType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +149,7 @@ bool RenderCmdBuffer::BindVAB(Renderable *ri)
|
|||||||
if(!ri)
|
if(!ri)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
const PrimitiveRenderBuffer *prb=ri->GetRenderBuffer();
|
const PrimitiveDataBuffer *prb=ri->GetRenderBuffer();
|
||||||
|
|
||||||
if(prb->vab_count<=0)
|
if(prb->vab_count<=0)
|
||||||
return(false);
|
return(false);
|
||||||
@ -153,10 +159,10 @@ bool RenderCmdBuffer::BindVAB(Renderable *ri)
|
|||||||
if(prd->vertex_count<=0)
|
if(prd->vertex_count<=0)
|
||||||
return(false);
|
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)
|
if(prb->ib_access->buffer)
|
||||||
BindIBO(prb->ibo,prd->index_start);
|
BindIBO(prb->ib_access);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -185,12 +191,12 @@ 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 PrimitiveRenderBuffer *prb,const PrimitiveRenderData *prd)
|
void RenderCmdBuffer::Draw(const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd)
|
||||||
{
|
{
|
||||||
if(!prb||!prd)
|
if(!prb||!prd)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (prb->ibo)
|
if (prb->ib_access->buffer)
|
||||||
DrawIndexed(prd->index_count);
|
DrawIndexed(prd->index_count);
|
||||||
else
|
else
|
||||||
Draw(prd->vertex_count);
|
Draw(prd->vertex_count);
|
||||||
|
@ -13,7 +13,7 @@ Material::Material(const AnsiString &n)
|
|||||||
{
|
{
|
||||||
name=n;
|
name=n;
|
||||||
|
|
||||||
primitive_render_buffer=nullptr;
|
vertex_input=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(primitive_render_buffer);
|
ReleaseVertexInput(vertex_input);
|
||||||
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 primitive_render_buffer->GetDefaultVIL();
|
return vertex_input->GetDefaultVIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
VIL *Material::CreateVIL(const VILConfig *format_map)
|
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)
|
bool Material::Release(VIL *vil)
|
||||||
{
|
{
|
||||||
return primitive_render_buffer->Release(vil);
|
return vertex_input->Release(vil);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint Material::GetVILCount()
|
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)
|
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;
|
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()
|
PrimitiveData::~PrimitiveData()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR_ARRAY(vab_access); //注意:这里并不释放VAB,在派生类中释放
|
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
||||||
}
|
}
|
||||||
|
|
||||||
const int PrimitiveData::GetVABCount()const
|
const int PrimitiveData::GetVABCount()const
|
||||||
@ -35,58 +35,13 @@ const int PrimitiveData::GetVABIndex(const AnsiString &name) const
|
|||||||
return vil->GetIndex(name);
|
return vil->GetIndex(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
VABAccess *PrimitiveData::GetVABAccess(const int index)
|
VAB *PrimitiveData::GetVAB(const int index)
|
||||||
{
|
{
|
||||||
if(index<0||index>=vil->GetCount())return(nullptr);
|
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
|
namespace
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -98,7 +53,10 @@ namespace
|
|||||||
|
|
||||||
public:
|
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)
|
PrimitiveDataPrivateBuffer(GPUDevice *dev,const VIL *_vil,const uint32_t vc):PrimitiveData(_vil,vc)
|
||||||
{
|
{
|
||||||
@ -107,83 +65,65 @@ namespace
|
|||||||
|
|
||||||
~PrimitiveDataPrivateBuffer() override
|
~PrimitiveDataPrivateBuffer() override
|
||||||
{
|
{
|
||||||
VABAccess *vab=vab_access;
|
VAB **vab=vab_list;
|
||||||
|
|
||||||
for(uint i=0;i<vil->GetCount();i++)
|
for(uint i=0;i<vil->GetCount();i++)
|
||||||
{
|
{
|
||||||
if(vab->vab)
|
if(*vab)
|
||||||
{
|
delete *vab;
|
||||||
delete vab->vab;
|
|
||||||
vab->vab=nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
++vab;
|
++vab;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ib_access.buffer)
|
if(ibo)
|
||||||
{
|
delete ibo;
|
||||||
delete ib_access.buffer;
|
|
||||||
ib_access.buffer=nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IBAccess *InitIBO(const uint32_t index_count,IndexType it) override
|
IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
|
||||||
{
|
{
|
||||||
if(!device)return(nullptr);
|
if(!device)return(nullptr);
|
||||||
|
|
||||||
if(ib_access.buffer)
|
if(ibo)delete ibo;
|
||||||
{
|
|
||||||
delete ib_access.buffer;
|
|
||||||
ib_access.buffer=nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ib_access.buffer=device->CreateIBO(it,index_count);
|
ibo=device->CreateIBO(it,ic);
|
||||||
|
|
||||||
if(!ib_access.buffer)
|
if(!ibo)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
ib_access.start=0;
|
index_count=ic;
|
||||||
ib_access.count=index_count;
|
|
||||||
|
|
||||||
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(!device)return(nullptr);
|
||||||
if(!vil)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);
|
return(nullptr);
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||||
|
|
||||||
if(!vif)return(nullptr);
|
if(!vif)return(nullptr);
|
||||||
|
|
||||||
if(vif->format!=format)
|
if(vif->format!=format)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
VABAccess *vaba=vab_access+index;
|
if(!vab_list[vab_index])
|
||||||
|
|
||||||
if(!vaba->vab)
|
|
||||||
{
|
{
|
||||||
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);
|
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
|
};//class PrimitiveDataPrivateBuffer:public PrimitiveData
|
||||||
|
|
||||||
@ -199,7 +139,8 @@ namespace
|
|||||||
|
|
||||||
public:
|
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)
|
PrimitiveDataVDM(VertexDataManager *_vdm,const uint32_t vc):PrimitiveData(_vdm->GetVIL(),vc)
|
||||||
{
|
{
|
||||||
@ -218,7 +159,7 @@ namespace
|
|||||||
vdm->ReleaseVAB(vab_node);
|
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(index_count<=0)return(nullptr);
|
||||||
if(!vdm)return(nullptr);
|
if(!vdm)return(nullptr);
|
||||||
@ -230,49 +171,39 @@ namespace
|
|||||||
if(!ib_node)
|
if(!ib_node)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
ib_access.buffer=vdm->GetIBO();
|
ibo=vdm->GetIBO();
|
||||||
ib_access.start =ib_node->GetStart();
|
|
||||||
ib_access.count =ib_node->GetCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(!vdm)return(nullptr);
|
||||||
if(!vil)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);
|
return(nullptr);
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||||
|
|
||||||
if(!vif)return(nullptr);
|
if(!vif)return(nullptr);
|
||||||
|
|
||||||
if(vif->format!=format)
|
if(vif->format!=format)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
VABAccess *vaba=vab_access+index;
|
if (!vab_list[vab_index])
|
||||||
|
|
||||||
if(!vaba->vab)
|
|
||||||
{
|
{
|
||||||
vaba->vab=vdm->GetVAB(index);
|
vab_list[vab_index]=vdm->GetVAB(vab_index);
|
||||||
|
|
||||||
if(!vaba->vab)
|
if(!vab_list[vab_index])
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
vaba->start=vab_node->GetStart();
|
|
||||||
vaba->count=vab_node->GetCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vaba->vab&&data)
|
if(vab_list[vab_index]&&data)
|
||||||
vaba->vab->Write(data,vaba->start,vaba->count);
|
vab_list[vab_index]->Write(data,vab_node->GetStart(),vertex_count);
|
||||||
|
|
||||||
return vaba;
|
return vab_list[vab_index];
|
||||||
}
|
}
|
||||||
};//class PrimitiveDataVDM:public PrimitiveData
|
};//class PrimitiveDataVDM:public PrimitiveData
|
||||||
}//namespace
|
}//namespace
|
||||||
|
@ -19,12 +19,13 @@ class PrimitiveData
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
const VIL * vil;
|
const VIL * vil;
|
||||||
|
|
||||||
uint32_t vertex_count;
|
uint32_t vertex_count;
|
||||||
|
uint32_t index_count;
|
||||||
|
|
||||||
VABAccess * vab_access;
|
VAB ** vab_list;
|
||||||
IBAccess ib_access;
|
IndexBuffer * ibo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -36,22 +37,20 @@ public:
|
|||||||
const uint32_t GetVertexCount ()const{return vertex_count;}
|
const uint32_t GetVertexCount ()const{return vertex_count;}
|
||||||
const int GetVABCount ()const;
|
const int GetVABCount ()const;
|
||||||
const int GetVABIndex (const AnsiString &name)const;
|
const int GetVABIndex (const AnsiString &name)const;
|
||||||
VABAccess * GetVABAccess (const int index);
|
VAB * GetVAB (const int index);
|
||||||
VABAccess * GetVABAccess (const AnsiString &name);
|
|
||||||
|
|
||||||
IBAccess * GetIBAccess (){return &ib_access;}
|
IndexBuffer * GetIBO (){return ibo;}
|
||||||
IndexBuffer * GetIBO (){return ib_access.buffer;}
|
uint32_t GetIndexCount ()const{return index_count;}
|
||||||
|
|
||||||
|
virtual int32_t GetVertexOffset ()const=0; ///<取得顶点偏移(注意是顶点不是字节)
|
||||||
|
virtual uint32_t GetFirstIndex ()const=0; ///<取得第一个索引
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual VertexDataManager *GetVDM()=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;
|
||||||
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;
|
|
||||||
};//class PrimitiveData
|
};//class PrimitiveData
|
||||||
|
|
||||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const uint32_t vc);
|
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const uint32_t vc);
|
||||||
PrimitiveData *CreatePrimitiveData(VertexDataManager *vdm,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();
|
ShaderCreateInfoVertex *vert=mci->GetVS();
|
||||||
|
|
||||||
if(vert)
|
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>
|
#include<hgl/log/LogInfo.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
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_count=c;
|
||||||
|
|
||||||
vab_list=hgl_zero_new<VkBuffer>(vab_count);
|
vab_list=hgl_zero_new<VkBuffer>(vab_count);
|
||||||
|
ibo=ib;
|
||||||
if(iba&&iba->buffer)
|
|
||||||
ibo=iba->buffer;
|
|
||||||
else
|
|
||||||
ibo=nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimitiveRenderBuffer::~PrimitiveRenderBuffer()
|
PrimitiveDataBuffer::~PrimitiveDataBuffer()
|
||||||
{
|
{
|
||||||
delete[] vab_list;
|
delete[] vab_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool PrimitiveRenderBuffer::Comp(const PrimitiveRenderBuffer *prb)const
|
const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *prb)const
|
||||||
{
|
{
|
||||||
if(!prb)return(false);
|
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(vab_list[i]!=prb->vab_list[i])return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ibo!=prb->ibo)return(false);
|
if(ibo!=prb->ibo)
|
||||||
|
return(false);
|
||||||
|
|
||||||
return(true);
|
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;
|
primitive=r;
|
||||||
pipeline=p;
|
pipeline=p;
|
||||||
mat_inst=mi;
|
mat_inst=mi;
|
||||||
|
|
||||||
primitive_render_buffer=prb;
|
primitive_data_buffer=prb;
|
||||||
primitive_render_data=prd;
|
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_count=bc;
|
||||||
|
|
||||||
vab_offset=new VkDeviceSize[vab_count];
|
|
||||||
|
|
||||||
vertex_count=vc;
|
vertex_count=vc;
|
||||||
|
vertex_offset=0;
|
||||||
|
|
||||||
if(iba&&iba->buffer)
|
first_index=0;
|
||||||
{
|
|
||||||
index_start=iba->start;
|
|
||||||
index_count=iba->count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimitiveRenderData::~PrimitiveRenderData()
|
PrimitiveRenderData::~PrimitiveRenderData()
|
||||||
{
|
{
|
||||||
delete[] vab_offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool PrimitiveRenderData::Comp(const PrimitiveRenderData *prd)const
|
const bool PrimitiveRenderData::Comp(const PrimitiveRenderData *prd)const
|
||||||
{
|
{
|
||||||
if(!prd)return(false);
|
if(!prd)return(false);
|
||||||
|
|
||||||
if(vab_count!=prd->vab_count)return(false);
|
return !memcmp(this,prd,sizeof(PrimitiveRenderData));
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||||
@ -104,10 +83,8 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const IBAccess *iba=prim->GetIBAccess();
|
PrimitiveDataBuffer *prb=new PrimitiveDataBuffer(input_count,prim->GetVertexCount(),prim->GetIBO());
|
||||||
|
PrimitiveRenderData *prd=new PrimitiveRenderData(input_count,prim->GetVertexCount());
|
||||||
PrimitiveRenderBuffer * prb=new PrimitiveRenderBuffer( input_count,prim->GetVertexCount(),iba);
|
|
||||||
PrimitiveRenderData * prd=new PrimitiveRenderData( input_count,prim->GetVertexCount(),iba);
|
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
||||||
|
|
||||||
@ -146,7 +123,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
prd->vab_offset[i]=vab_access->start;
|
prb->vab_offset[i]=vab_access->start;
|
||||||
prb->vab_list[i]=vab_access->vab->GetBuffer();
|
prb->vab_list[i]=vab_access->vab->GetBuffer();
|
||||||
++vif;
|
++vif;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user