diff --git a/inc/hgl/graph/PrimitiveCreater.h b/inc/hgl/graph/PrimitiveCreater.h index ed6cd60b..2ddfbf05 100644 --- a/inc/hgl/graph/PrimitiveCreater.h +++ b/inc/hgl/graph/PrimitiveCreater.h @@ -4,6 +4,8 @@ #include #include #include +#include + namespace hgl { namespace graph diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 6fc21d9a..e256e831 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -59,6 +59,20 @@ struct VertexInputData; class VertexAttribBuffer; using VAB=VertexAttribBuffer; +struct VABAccess +{ + VAB *vab; + VkDeviceSize start; + + void *map_ptr; + +public: + + CompOperatorMemcmp(const VABAccess &); +};//class VABAccess + +using VABAccessMap=Map; + class IndexBuffer; struct IndexBufferAccess diff --git a/inc/hgl/graph/VKPrimitive.h b/inc/hgl/graph/VKPrimitive.h index b3745783..567b9c1b 100644 --- a/inc/hgl/graph/VKPrimitive.h +++ b/inc/hgl/graph/VKPrimitive.h @@ -3,9 +3,11 @@ #include #include -#include -#include +#include +#include + VK_NAMESPACE_BEGIN + /** * 单一图元数据 */ @@ -26,7 +28,14 @@ protected: protected: - friend class RenderableNode; + bool SetVAB(const AnsiString &name,VAB *vb,VkDeviceSize start=0); + + bool SetIndex(IndexBuffer *ib,VkDeviceSize start,const VkDeviceSize index_count); + + void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;} + + friend class PrimitiveCreater; + friend class RenderablePrimitiveCreater; public: @@ -39,22 +48,14 @@ public: virtual ~Primitive()=default; - void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;} - const AABB & GetBoundingBox()const {return BoundingBox;} - - bool SetVAB(const AnsiString &name,VAB *vb,VkDeviceSize start=0); - - bool SetIndex(IndexBuffer *ib,VkDeviceSize start,const VkDeviceSize index_count); - public: - const VkDeviceSize GetVertexCount ()const {return vertex_count;} + const VkDeviceSize GetVertexCount ()const{return vertex_count;} + const int GetVACount ()const{return buffer_list.GetCount();} + const bool GetVABAccess (const AnsiString &,VABAccess *); + const IBAccess * GetIBAccess ()const{return ib_access.buffer?&ib_access:nullptr;} - const int GetBufferCount ()const {return buffer_list.GetCount();} - - bool GetVABAccess (const AnsiString &,VABAccess *); - - const IBAccess * GetIBAccess ()const {return ib_access.buffer?&ib_access:nullptr;} + const AABB & GetBoundingBox ()const{return BoundingBox;} };//class Primitive VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE diff --git a/inc/hgl/graph/VKPrimitiveData.h b/inc/hgl/graph/VKPrimitiveData.h index f31c3f5e..7a3f7663 100644 --- a/inc/hgl/graph/VKPrimitiveData.h +++ b/inc/hgl/graph/VKPrimitiveData.h @@ -1,46 +1,101 @@ #pragma once - -#include -#include -#include - -VK_NAMESPACE_BEGIN - -/* - 1.截止2024.4.27,根据vulkan.gpuinfo.org统计,只有9%的设备maxVertexInputAttributes为16,不存在低于16的设备。 - 9.0%的设备为28 - 31 - 70.7%的设备为32 - 9.6%的设备为64 - - 由于我们暂时没有发现需要使用16个以上属性的情况,所以这里暂定使用16。 - (如果时间过去久远,可再次查询此值是否可改成更高的值,以及是否需要) - - 2.为何va_name使用char[][]而不是String以及动态分配内存? - - 就是为了必避动态分配内存,以及可以直接memcpy处理,所以此处这样定义。 -*/ - -struct VABAccessInfo -{ - char va_name[VERTEX_ATTRIB_NAME_MAX_LENGTH+1]; - VABAccess vab_access; -}; - -constexpr const uint HGL_MAX_VERTEX_ATTRIB_COUNT=16; ///<最大顶点属性数量 - -struct PrimitiveData -{ - VkDeviceSize vertex_count; - - uint32_t va_count; - - VABAccessInfo vab_list[HGL_MAX_VERTEX_ATTRIB_COUNT]; - - IBAccess ib_access; - - AABB BoundingBox; -};//struct PrimitiveData - -constexpr const uint PRIMITIVE_DATA_SIZE=sizeof(PrimitiveData); +// +//#include +//#include +//#include +// +//VK_NAMESPACE_BEGIN +// +///* +// 1.截止2024.4.27,根据vulkan.gpuinfo.org统计,只有9%的设备maxVertexInputAttributes为16,不存在低于16的设备。 +// 9.0%的设备为28 - 31 +// 70.7%的设备为32 +// 9.6%的设备为64 +// +// 由于我们暂时没有发现需要使用16个以上属性的情况,所以这里暂定使用16。 +// (如果时间过去久远,可再次查询此值是否可改成更高的值,以及是否需要) +// +// 2.为何va_name使用char[][]而不是String以及动态分配内存? +// +// 就是为了必避动态分配内存,以及可以直接memcpy处理,所以此处这样定义。 +//*/ +// +//struct VABAccessInfo +//{ +// char va_name[VERTEX_ATTRIB_NAME_MAX_LENGTH+1]; +// VABAccess vab_access; +//}; +// +//constexpr const uint HGL_MAX_VERTEX_ATTRIB_COUNT=16; ///<最大顶点属性数量 +// +//struct PrimitiveData +//{ +// VkDeviceSize vertex_count; +// +// uint32_t va_count; +// +// VABAccessInfo vab_list[HGL_MAX_VERTEX_ATTRIB_COUNT]; +// +// IBAccess ib_access; +// +// AABB BoundingBox; +// +//public: +// +// void Clear() +// { +// hgl_zero(*this); +// } +// +// const int GetVABIndex(const char *name)const +// { +// for(int i=0;i=HGL_MAX_VERTEX_ATTRIB_COUNT) +// return(-1); +// +// VABAccessInfo *vai=vab_list+va_count; +// +// hgl::strcpy(vai->va_name,VERTEX_ATTRIB_NAME_MAX_LENGTH,name); +// vai->vab_access.vab=vab; +// vai->vab_access.start=start; +// +// #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(va_count++); +// } +//};//struct PrimitiveData +// +//constexpr const uint PRIMITIVE_DATA_SIZE=sizeof(PrimitiveData); VK_NAMESPACE_END diff --git a/inc/hgl/graph/VKVertexAttribBuffer.h b/inc/hgl/graph/VKVertexAttribBuffer.h index 478c4bcd..2958e8f3 100644 --- a/inc/hgl/graph/VKVertexAttribBuffer.h +++ b/inc/hgl/graph/VKVertexAttribBuffer.h @@ -36,20 +36,6 @@ namespace hgl };//class VertexAttribBuffer:public DeviceBuffer using VAB=VertexAttribBuffer; - - struct VABAccess - { - VAB *vab; - VkDeviceSize start; - - void *map_ptr; - - public: - - CompOperatorMemcmp(const VABAccess &); - };//class VABAccess - - using VABAccessMap=Map; }//namespace graph }//namespace hgl #endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE diff --git a/src/SceneGraph/PrimitiveCreater.cpp b/src/SceneGraph/PrimitiveCreater.cpp index 360be994..d3ae13b1 100644 --- a/src/SceneGraph/PrimitiveCreater.cpp +++ b/src/SceneGraph/PrimitiveCreater.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include namespace hgl diff --git a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp index 010e4878..741b697f 100644 --- a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp +++ b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp @@ -4,6 +4,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN RenderCmdBuffer::RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb):GPUCmdBuffer(attr,cb) diff --git a/src/SceneGraph/Vulkan/VKPrimitive.cpp b/src/SceneGraph/Vulkan/VKPrimitive.cpp index 5e127f63..91c29e8d 100644 --- a/src/SceneGraph/Vulkan/VKPrimitive.cpp +++ b/src/SceneGraph/Vulkan/VKPrimitive.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -52,7 +53,7 @@ bool Primitive::SetVAB(const AnsiString &name,VAB *vab,VkDeviceSize start) return(true); } -bool Primitive::GetVABAccess(const AnsiString &name,VABAccess *vad) +const bool Primitive::GetVABAccess(const AnsiString &name,VABAccess *vad) { if(name.IsEmpty())return(false); if(!vad)return(false); diff --git a/src/SceneGraph/Vulkan/VKRenderResource.cpp b/src/SceneGraph/Vulkan/VKRenderResource.cpp index af09cb4e..f7b3a469 100644 --- a/src/SceneGraph/Vulkan/VKRenderResource.cpp +++ b/src/SceneGraph/Vulkan/VKRenderResource.cpp @@ -3,6 +3,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN VAB *RenderResource::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode) diff --git a/src/SceneGraph/Vulkan/VKRenderable.cpp b/src/SceneGraph/Vulkan/VKRenderable.cpp index 5bd646af..466ecfac 100644 --- a/src/SceneGraph/Vulkan/VKRenderable.cpp +++ b/src/SceneGraph/Vulkan/VKRenderable.cpp @@ -51,7 +51,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) const uint32_t input_count=vil->GetCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的 const UTF8String &mtl_name=mi->GetMaterial()->GetName(); - if(prim->GetBufferCount()GetVACount()