diff --git a/inc/hgl/graph/PrimitiveCreater.h b/inc/hgl/graph/PrimitiveCreater.h index 48883e5c..ed6cd60b 100644 --- a/inc/hgl/graph/PrimitiveCreater.h +++ b/inc/hgl/graph/PrimitiveCreater.h @@ -89,24 +89,6 @@ namespace hgl return(true); } - //template - //T * CreateIBO(const uint count,const T *data=nullptr) ///<创建索引缓冲区 - //{ - // if(ibo) - // return(nullptr); - // - // ibo=db->CreateIBO(IT,count,data); - - // if(!ibo) - // return(nullptr); - - // return (T *)ibo->Map(); - //} - - //uint8 * CreateIBO8 (uint count,const uint8 *data=nullptr){return CreateIBO(count,data);} ///<创建8位的索引缓冲区 - //uint16 * CreateIBO16(uint count,const uint16 *data=nullptr){return CreateIBO(count,data);} ///<创建16位的索引缓冲区 - //uint32 * CreateIBO32(uint count,const uint32 *data=nullptr){return CreateIBO(count,data);} ///<创建32位的索引缓冲区 - virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象 };//class PrimitiveCreater }//namespace graph diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 69f8a80a..6fc21d9a 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -64,7 +64,8 @@ class IndexBuffer; struct IndexBufferAccess { IndexBuffer *buffer=nullptr; - VkDeviceSize offset=0; + VkDeviceSize start=0; + VkDeviceSize count=0; }; using IBAccess=IndexBufferAccess; diff --git a/inc/hgl/graph/VKCommandBuffer.h b/inc/hgl/graph/VKCommandBuffer.h index a9bea20c..5dfceb4f 100644 --- a/inc/hgl/graph/VKCommandBuffer.h +++ b/inc/hgl/graph/VKCommandBuffer.h @@ -170,7 +170,7 @@ public: return(true); } - void BindIBO(const IBAccess *); +// void BindIBO(const IBAccess *); bool BindVBO(Renderable *); @@ -192,8 +192,8 @@ public: //draw void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);} void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);} - template void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);} - template void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);} +// template void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);} +// template void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);} void DrawIndirect (VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )); void DrawIndexedIndirect(VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )); @@ -201,6 +201,7 @@ public: //draw void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);} void Draw (const VertexInputData *vid); + void DrawIndexed (const IBAccess *iba,const uint32_t instance_count); public: //dynamic state };//class RenderCmdBuffer:public GPUCmdBuffer diff --git a/inc/hgl/graph/VKPrimitive.h b/inc/hgl/graph/VKPrimitive.h index 4b77e108..0df5ecd0 100644 --- a/inc/hgl/graph/VKPrimitive.h +++ b/inc/hgl/graph/VKPrimitive.h @@ -16,7 +16,7 @@ class Primitive protected: - uint32_t vertex_count; + VkDeviceSize vertex_count; VABAccessMap buffer_list; @@ -30,7 +30,7 @@ protected: public: - Primitive(GPUDevice *dev,const AnsiString &n,const uint32_t vc=0) + Primitive(GPUDevice *dev,const AnsiString &n,const VkDeviceSize vc=0) { device=dev; prim_name=n; @@ -42,13 +42,13 @@ public: void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;} const AABB & GetBoundingBox()const {return BoundingBox;} - bool Set(const AnsiString &name,VAB *vb,VkDeviceSize offset=0); + bool SetVAB(const AnsiString &name,VAB *vb,VkDeviceSize start=0); - bool Set(IndexBuffer *ib,VkDeviceSize offset=0); + bool SetIndex(IndexBuffer *ib,VkDeviceSize start,const VkDeviceSize index_count); public: - const uint32_t GetVertexCount ()const {return vertex_count;} + const VkDeviceSize GetVertexCount ()const {return vertex_count;} bool GetVABAccess (const AnsiString &,VABAccess *); const int GetBufferCount ()const {return buffer_list.GetCount();} diff --git a/inc/hgl/graph/VKPrimitiveData.h b/inc/hgl/graph/VKPrimitiveData.h index 64c80d97..da54c0a5 100644 --- a/inc/hgl/graph/VKPrimitiveData.h +++ b/inc/hgl/graph/VKPrimitiveData.h @@ -8,7 +8,7 @@ VK_NAMESPACE_BEGIN struct PrimitiveData { - uint32_t vertex_count; + VkDeviceSize vertex_count; uint32_t va_count; diff --git a/inc/hgl/graph/VKRenderablePrimitiveCreater.h b/inc/hgl/graph/VKRenderablePrimitiveCreater.h index bf584117..5e7c4095 100644 --- a/inc/hgl/graph/VKRenderablePrimitiveCreater.h +++ b/inc/hgl/graph/VKRenderablePrimitiveCreater.h @@ -11,13 +11,13 @@ class RenderablePrimitiveCreater { RenderResource *rr; - uint32_t vertex_count; + VkDeviceSize vertex_count; Primitive *prim; public: - RenderablePrimitiveCreater(RenderResource *_rr,const AnsiString &name,uint32_t vc) + RenderablePrimitiveCreater(RenderResource *_rr,const AnsiString &name,VkDeviceSize vc) { rr=_rr; vertex_count=vc; @@ -32,18 +32,18 @@ public: if(!vab) return(nullptr); - prim->Set(name,vab); + prim->SetVAB(name,vab); return(vab); } - IndexBuffer *SetIBO(const IndexType &it,const void *buf,const uint32_t index_count) + IndexBuffer *SetIndex(const IndexType &it,const void *buf,const VkDeviceSize index_count) { IndexBuffer *ibo=rr->CreateIBO(it,index_count,buf); if(!ibo) return(nullptr); - prim->Set(ibo); + prim->SetIndex(ibo,0,index_count); return(ibo); } diff --git a/inc/hgl/graph/VKVertexAttribBuffer.h b/inc/hgl/graph/VKVertexAttribBuffer.h index 96e683cc..478c4bcd 100644 --- a/inc/hgl/graph/VKVertexAttribBuffer.h +++ b/inc/hgl/graph/VKVertexAttribBuffer.h @@ -40,8 +40,7 @@ namespace hgl struct VABAccess { VAB *vab; - VkDeviceSize offset; - VkDeviceSize size; + VkDeviceSize start; void *map_ptr; diff --git a/inc/hgl/graph/VertexAttribDataAccess.h b/inc/hgl/graph/VertexAttribDataAccess.h index b6eee615..edce72a5 100644 --- a/inc/hgl/graph/VertexAttribDataAccess.h +++ b/inc/hgl/graph/VertexAttribDataAccess.h @@ -51,14 +51,14 @@ namespace hgl /** * 取得数据区地址 - * @param offset 从第几个数据开始访问 + * @param start 从第几个数据开始访问 * @return 访问地址 */ T *Get(uint32_t offset=0) { if(!data||offset>=count) { - LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,offset:")+OSString::numberOf(offset)); + LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,start:")+OSString::numberOf(offset)); return(nullptr); } @@ -67,14 +67,14 @@ namespace hgl /** * 开始访问数据区 - * @param offset 从第几个数据开始访问 + * @param start 从第几个数据开始访问 * @return 访问地址 */ T *Begin(uint32_t offset=0) { if(access) { - LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,offset:")+OSString::numberOf(offset)); + LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,start:")+OSString::numberOf(offset)); return(nullptr); } diff --git a/src/SceneGraph/MaterialRenderList.cpp b/src/SceneGraph/MaterialRenderList.cpp index 6897fee9..e8973d2b 100644 --- a/src/SceneGraph/MaterialRenderList.cpp +++ b/src/SceneGraph/MaterialRenderList.cpp @@ -260,9 +260,7 @@ void MaterialRenderList::Render(RenderItem *ri) if(iba->buffer) { - cmd_buf->BindIBO(iba); - - cmd_buf->DrawIndexed(iba->buffer->GetCount(),ri->count); + cmd_buf->DrawIndexed(iba,ri->count); } else { diff --git a/src/SceneGraph/PrimitiveCreater.cpp b/src/SceneGraph/PrimitiveCreater.cpp index 8c39d615..360be994 100644 --- a/src/SceneGraph/PrimitiveCreater.cpp +++ b/src/SceneGraph/PrimitiveCreater.cpp @@ -173,7 +173,7 @@ namespace hgl if((*sp)->value.map_ptr) (*sp)->value.vab->Unmap(); - primitive->Set((*sp)->key,(*sp)->value.vab); + primitive->SetVAB((*sp)->key,(*sp)->value.vab); } else { @@ -187,7 +187,7 @@ namespace hgl if(ibo) { ibo->Unmap(); - primitive->Set(ibo); + primitive->SetIndex(ibo,0,index_number); db->Add(ibo); ibo=nullptr; //避免释构函数删除 diff --git a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp index 49c7cbfd..010e4878 100644 --- a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp +++ b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp @@ -129,13 +129,13 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl) return(true); } -void RenderCmdBuffer::BindIBO(const IBAccess *iba) -{ - vkCmdBindIndexBuffer( cmd_buf, - iba->buffer->GetBuffer(), - iba->offset, - VkIndexType(iba->buffer->GetType())); -} +//void RenderCmdBuffer::BindIBO(const IBAccess *iba) +//{ +// vkCmdBindIndexBuffer( cmd_buf, +// iba->buffer->GetBuffer(), +// iba->start, +// VkIndexType(iba->buffer->GetType())); +//} bool RenderCmdBuffer::BindVBO(Renderable *ri) { @@ -154,7 +154,7 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri) if(indices_buffer) vkCmdBindIndexBuffer(cmd_buf, indices_buffer->GetBuffer(), - vid->ib_access->offset, + vid->ib_access->start, VkIndexType(indices_buffer->GetType())); return(true); @@ -187,8 +187,20 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer, void RenderCmdBuffer::Draw(const VertexInputData *vid) { if (vid->ib_access->buffer) - DrawIndexed(vid->ib_access->buffer->GetCount()); + DrawIndexed(vid->ib_access->count); else Draw(vid->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, + VkIndexType(iba->buffer->GetType())); + + vkCmdDrawIndexed(cmd_buf,iba->count,instance_count,0,0,0); +} VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKPrimitive.cpp b/src/SceneGraph/Vulkan/VKPrimitive.cpp index c9a5516e..5e127f63 100644 --- a/src/SceneGraph/Vulkan/VKPrimitive.cpp +++ b/src/SceneGraph/Vulkan/VKPrimitive.cpp @@ -27,7 +27,7 @@ VK_NAMESPACE_BEGIN // return(true); //} -bool Primitive::Set(const AnsiString &name,VAB *vab,VkDeviceSize offset) +bool Primitive::SetVAB(const AnsiString &name,VAB *vab,VkDeviceSize start) { if(!vab)return(false); if(buffer_list.KeyExist(name))return(false); @@ -35,8 +35,7 @@ bool Primitive::Set(const AnsiString &name,VAB *vab,VkDeviceSize offset) VABAccess vad; vad.vab=vab; - vad.offset=offset; - vad.size=vab->GetBytes(); + vad.start=start; buffer_list.Add(name,vad); @@ -61,12 +60,13 @@ bool Primitive::GetVABAccess(const AnsiString &name,VABAccess *vad) return buffer_list.Get(name,*vad); } -bool Primitive::Set(IndexBuffer *ib,VkDeviceSize offset) +bool Primitive::SetIndex(IndexBuffer *ib,VkDeviceSize start,const VkDeviceSize index_count) { if(!ib)return(false); ib_access.buffer=ib; - ib_access.offset=offset; + ib_access.start=start; + ib_access.count=index_count; #ifdef _DEBUG DebugUtils *du=device->GetDebugUtils(); diff --git a/src/SceneGraph/Vulkan/VKRenderable.cpp b/src/SceneGraph/Vulkan/VKRenderable.cpp index 26f54727..c92c47ec 100644 --- a/src/SceneGraph/Vulkan/VKRenderable.cpp +++ b/src/SceneGraph/Vulkan/VKRenderable.cpp @@ -95,7 +95,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) return(nullptr); } - vid->buffer_offset[i]=vad.offset; + vid->buffer_offset[i]=vad.start; vid->buffer_list[i]=vab->GetBuffer(); ++vif; }