From bd0a3d8be142d79aba20da553bf710d3aa770120 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 15 Jan 2025 02:42:04 +0800 Subject: [PATCH] to support newly String<>/IDName/Compare --- CMAssetsManage | 2 +- CMCore | 2 +- CMPlatform | 2 +- CMSceneGraph | 2 +- CMUtil | 2 +- example/GUI/DrawText.cpp | 2 +- example/Gizmo/Gizmo3DMove.cpp | 1 + example/Gizmo/Gizmo3DRotate.cpp | 1 + example/Gizmo/Gizmo3DScale.cpp | 1 + example/Gizmo/GizmoResource.cpp | 1 + inc/hgl/graph/MaterialRenderList.h | 51 +- inc/hgl/graph/MaterialRenderMap.h | 2 +- inc/hgl/graph/RenderNode.h | 14 +- inc/hgl/graph/SceneNode.h | 16 +- inc/hgl/graph/VKDeviceRenderPassManage.h | 11 +- inc/hgl/graph/VKRenderable.h | 9 +- inc/hgl/graph/font/Font.h | 4 +- inc/hgl/graph/font/TextLayout.h | 4 +- inc/hgl/graph/font/TextRender.h | 6 +- inc/hgl/graph/font/TileFont.h | 2 +- inc/hgl/graph/mtl/Material2DCreateConfig.h | 8 +- inc/hgl/graph/mtl/Material3DCreateConfig.h | 58 +- inc/hgl/graph/mtl/MaterialConfig.h | 6 +- inc/hgl/graph/mtl/ShaderVariableType.h | 873 ++++++++---------- inc/hgl/shadergen/ShaderCreateInfo.h | 2 +- src/SceneGraph/MaterialRenderList.cpp | 70 +- src/SceneGraph/RenderList.cpp | 13 +- src/SceneGraph/Vulkan/VKDeviceMaterial.cpp | 4 +- .../Vulkan/VKDeviceRenderPassManage.cpp | 8 +- src/SceneGraph/Vulkan/VKRenderResource.cpp | 2 +- src/SceneGraph/Vulkan/VKRenderable.cpp | 32 +- src/ShaderGen/ShaderLibrary.cpp | 2 +- src/ShaderGen/ShaderVariableType.cpp | 108 +++ 33 files changed, 644 insertions(+), 677 deletions(-) diff --git a/CMAssetsManage b/CMAssetsManage index 85436b5a..0fae4623 160000 --- a/CMAssetsManage +++ b/CMAssetsManage @@ -1 +1 @@ -Subproject commit 85436b5a7b0bc9347fcd3321a6895464470f1353 +Subproject commit 0fae462338cd01c5a26d0a8f0175fe3729a65c94 diff --git a/CMCore b/CMCore index 7c08fbc5..5aad7d81 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 7c08fbc530c97394932bfafab73d35073b49f7d8 +Subproject commit 5aad7d81419d02141b3b3f53661e2c8e3e763163 diff --git a/CMPlatform b/CMPlatform index 103b0d84..aa7abe47 160000 --- a/CMPlatform +++ b/CMPlatform @@ -1 +1 @@ -Subproject commit 103b0d845dc9fdbc10e2e40ab0fa346d133dc1ae +Subproject commit aa7abe47631cdb687528400409ef295fd2c050b8 diff --git a/CMSceneGraph b/CMSceneGraph index c958a6cb..4949c2e3 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit c958a6cb2ac4a52716eabc1c45eba184f4c7e46c +Subproject commit 4949c2e3e82c8a88a783579aff120617c4ecfdab diff --git a/CMUtil b/CMUtil index f7dce030..57ff3a70 160000 --- a/CMUtil +++ b/CMUtil @@ -1 +1 @@ -Subproject commit f7dce0304822280d0db23ae607783b7c3cd183fa +Subproject commit 57ff3a70c99265ed7bb97b3b6840709e84bac0c1 diff --git a/example/GUI/DrawText.cpp b/example/GUI/DrawText.cpp index 31ab7cf1..84280690 100644 --- a/example/GUI/DrawText.cpp +++ b/example/GUI/DrawText.cpp @@ -28,7 +28,7 @@ private: bool InitTextRenderable() { - UTF16String str; + U16String str; LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt")); diff --git a/example/Gizmo/Gizmo3DMove.cpp b/example/Gizmo/Gizmo3DMove.cpp index f9e07a53..f666e1aa 100644 --- a/example/Gizmo/Gizmo3DMove.cpp +++ b/example/Gizmo/Gizmo3DMove.cpp @@ -22,6 +22,7 @@ */ #include"GizmoResource.h" +#include #include #include diff --git a/example/Gizmo/Gizmo3DRotate.cpp b/example/Gizmo/Gizmo3DRotate.cpp index 25dd3020..8b39f211 100644 --- a/example/Gizmo/Gizmo3DRotate.cpp +++ b/example/Gizmo/Gizmo3DRotate.cpp @@ -1,4 +1,5 @@ #include"GizmoResource.h" +#include #include #include diff --git a/example/Gizmo/Gizmo3DScale.cpp b/example/Gizmo/Gizmo3DScale.cpp index 2a22b3b1..4ecb5319 100644 --- a/example/Gizmo/Gizmo3DScale.cpp +++ b/example/Gizmo/Gizmo3DScale.cpp @@ -22,6 +22,7 @@ */ #include"GizmoResource.h" +#include #include #include diff --git a/example/Gizmo/GizmoResource.cpp b/example/Gizmo/GizmoResource.cpp index 5e2bdb28..fee3bbb3 100644 --- a/example/Gizmo/GizmoResource.cpp +++ b/example/Gizmo/GizmoResource.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include"GizmoResource.h" VK_NAMESPACE_BEGIN diff --git a/inc/hgl/graph/MaterialRenderList.h b/inc/hgl/graph/MaterialRenderList.h index 84991ca0..7784b3c6 100644 --- a/inc/hgl/graph/MaterialRenderList.h +++ b/inc/hgl/graph/MaterialRenderList.h @@ -8,15 +8,48 @@ class RenderAssignBuffer; class SceneNode; struct CameraInfo; +struct RenderPipelineIndex:public Comparator +{ + Material *material; + Pipeline *pipeline; + +public: + + const int compare(const RenderPipelineIndex &rli)const override + { + if(materialrli.material)return(1); + + if(pipelinerli.pipeline)return(1); + + return(0); + } + +public: + + RenderPipelineIndex() + { + material=nullptr; + pipeline=nullptr; + } + + RenderPipelineIndex(Material *m,Pipeline *p) + { + material=m; + pipeline=p; + } +};//struct RenderPipelineIndex + /** -* 同一材质的对象渲染列表 +* 同一材质与管线的渲染列表 */ class MaterialRenderList { GPUDevice *device; RenderCmdBuffer *cmd_buf; - Material *material; + RenderPipelineIndex rp_index; CameraInfo *camera_info; @@ -33,7 +66,6 @@ private: uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB) uint32_t instance_count; - Pipeline * pipeline; MaterialInstance * mi; const PrimitiveDataBuffer * pdb; @@ -60,7 +92,6 @@ protected: VABList * vab_list; - Pipeline * last_pipeline; const PrimitiveDataBuffer * last_data_buffer; const VDM * last_vdm; const PrimitiveRenderData * last_render_data; @@ -75,20 +106,14 @@ protected: public: - MaterialRenderList(GPUDevice *d,bool l2w,Material *m); + MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi); ~MaterialRenderList(); void Add(SceneNode *); - void SetCameraInfo(CameraInfo *ci) - { - camera_info=ci; - } + void SetCameraInfo(CameraInfo *ci){camera_info=ci;} - void Clear() - { - rn_list.Clear(); - } + void Clear(){rn_list.Clear();} void End(); diff --git a/inc/hgl/graph/MaterialRenderMap.h b/inc/hgl/graph/MaterialRenderMap.h index e2487d87..91034c66 100644 --- a/inc/hgl/graph/MaterialRenderMap.h +++ b/inc/hgl/graph/MaterialRenderMap.h @@ -2,7 +2,7 @@ #include VK_NAMESPACE_BEGIN -class MaterialRenderMap:public ObjectMap +class MaterialRenderMap:public ObjectMap { public: diff --git a/inc/hgl/graph/RenderNode.h b/inc/hgl/graph/RenderNode.h index 1ee2ffe3..19c62508 100644 --- a/inc/hgl/graph/RenderNode.h +++ b/inc/hgl/graph/RenderNode.h @@ -11,9 +11,9 @@ namespace hgl class MaterialInstance; class SceneNode; - struct RenderNode + struct RenderNode:public Comparator { - uint index; ///<在MaterialRenderList中的索引 + uint index; ///<在MaterialRenderList中的索引 SceneNode * scene_node; @@ -22,6 +22,11 @@ namespace hgl Vector3f world_position; float to_camera_distance; + + public: + + //该函数位于MaterialRenderList.cpp + const int compare(const RenderNode &)const override; }; using RenderNodeList=List; @@ -29,5 +34,10 @@ namespace hgl using MaterialInstanceSets=SortedSet; ///<材质实例集合 }//namespace graph + + template<> inline const int ItemComparator::compare(const graph::RenderNode &a,const graph::RenderNode &b) + { + return a.compare(b); + } }//namespace hgl #endif//HGL_GRAPH_RENDER_NODE_INCLUDE diff --git a/inc/hgl/graph/SceneNode.h b/inc/hgl/graph/SceneNode.h index ea7771ee..85d30dd4 100644 --- a/inc/hgl/graph/SceneNode.h +++ b/inc/hgl/graph/SceneNode.h @@ -10,7 +10,7 @@ namespace hgl namespace graph { using SceneNodeID =uint64; - using SceneNodeName =UTF16IDName; + using SceneNodeName =U16IDName; /** * 场景节点数据类
@@ -19,6 +19,8 @@ namespace hgl */ class SceneNode:public SceneOrient ///场景节点类 { + SceneNode *Owner; ///<上级节点 + SceneNodeID NodeID; ///<节点ID SceneNodeName NodeName; ///<节点名称 @@ -59,6 +61,8 @@ namespace hgl { SceneOrient::Clear(); + Owner=nullptr; + BoundingBox.SetZero(); LocalBoundingBox.SetZero(); @@ -74,8 +78,13 @@ namespace hgl return(true); } - Renderable *GetRenderable(){return render_obj;} - void SetRenderable(Renderable *); + void SetOwner(SceneNode *sn) {Owner=sn;} + SceneNode * GetOwner() noexcept{return Owner;} + const SceneNode * GetOwner()const noexcept{return Owner;} + + void SetRenderable(Renderable *); + Renderable *GetRenderable() noexcept{return render_obj;} + const Renderable *GetRenderable()const noexcept{return render_obj;} SceneNode *Add(SceneNode *sn) { @@ -83,6 +92,7 @@ namespace hgl return(nullptr); ChildNode.Add(sn); + sn->SetOwner(this); return sn; } diff --git a/inc/hgl/graph/VKDeviceRenderPassManage.h b/inc/hgl/graph/VKDeviceRenderPassManage.h index 11f3fbb6..d6249582 100644 --- a/inc/hgl/graph/VKDeviceRenderPassManage.h +++ b/inc/hgl/graph/VKDeviceRenderPassManage.h @@ -1,12 +1,16 @@ -#ifndef HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE -#define HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE +#pragma once #include #include #include VK_NAMESPACE_BEGIN -using RenderPassHASHCode=util::HashCodeSHA1LE; + +using RenderPassHASHCode=util::HashCode<128/8>; +inline util::Hash *CreateRenderPassHash() +{ + return util::CreateHash(util::HASH::xxH3_128); +} class DeviceRenderPassManage { @@ -34,4 +38,3 @@ private: RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2); };//class DeviceRenderPassManage VK_NAMESPACE_END -#endif//HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE diff --git a/inc/hgl/graph/VKRenderable.h b/inc/hgl/graph/VKRenderable.h index 5a40e799..9d98b662 100644 --- a/inc/hgl/graph/VKRenderable.h +++ b/inc/hgl/graph/VKRenderable.h @@ -12,7 +12,7 @@ VK_NAMESPACE_BEGIN * 原始图元数据缓冲区
* 提供在渲染之前的数据绑定信息 */ -struct PrimitiveDataBuffer +struct PrimitiveDataBuffer:public Comparator { uint32_t vab_count; VkBuffer * vab_list; @@ -32,14 +32,14 @@ public: PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr); ~PrimitiveDataBuffer(); - const bool Comp(const PrimitiveDataBuffer *pdb)const; + const int compare(const PrimitiveDataBuffer &pdb)const override; };//struct PrimitiveDataBuffer /** * 原始图元渲染数据
* 提供在渲染时的数据 */ -struct PrimitiveRenderData +struct PrimitiveRenderData:public ComparatorData { //因为要VAB是流式访问,所以我们这个结构会被用做排序依据 //也因此,把vertex_offset放在最前面 @@ -59,9 +59,6 @@ public: vertex_offset =vo; first_index =fi; } - - CompOperatorMemcmp(const PrimitiveRenderData &); - CompOperatorMemcmpPointer(PrimitiveRenderData); }; /** diff --git a/inc/hgl/graph/font/Font.h b/inc/hgl/graph/font/Font.h index c630996b..5a1395a3 100644 --- a/inc/hgl/graph/font/Font.h +++ b/inc/hgl/graph/font/Font.h @@ -12,7 +12,7 @@ namespace hgl /** * 字体信息 */ - struct Font + struct Font:public ComparatorData { os_char name[MAX_FONT_NAME_LENGTH]; ///<字体名称 @@ -28,8 +28,6 @@ namespace hgl Font(); Font(const os_char *,int,int,bool b=false,bool i=false,bool=true); - - CompOperatorMemcmp(const Font &); ///<比较操作符重载 };//struct Font }//namespace graph }//namespace hgl diff --git a/inc/hgl/graph/font/TextLayout.h b/inc/hgl/graph/font/TextLayout.h index 0f417b0b..6796f1f5 100644 --- a/inc/hgl/graph/font/TextLayout.h +++ b/inc/hgl/graph/font/TextLayout.h @@ -100,8 +100,8 @@ namespace hgl int draw_chars_count; ///<要绘制字符列表 - SortedSet chars_sets; ///<不重复字符统计缓冲区 - SortedSet clear_chars_sets; ///<待清除的字符合集 + SortedSets chars_sets; ///<不重复字符统计缓冲区 + SortedSets clear_chars_sets; ///<待清除的字符合集 TileUVFloatMap chars_uv; ///<所有要绘制字符的uv struct CharDrawAttr diff --git a/inc/hgl/graph/font/TextRender.h b/inc/hgl/graph/font/TextRender.h index 3675b95d..6322f7ba 100644 --- a/inc/hgl/graph/font/TextRender.h +++ b/inc/hgl/graph/font/TextRender.h @@ -33,7 +33,7 @@ namespace hgl Color4f color; DeviceBuffer * ubo_color; - SortedSet tr_sets; + SortedSets tr_sets; private: @@ -54,9 +54,9 @@ namespace hgl public: TextPrimitive *CreatePrimitive(); - TextPrimitive *CreatePrimitive(const UTF16String &str); + TextPrimitive *CreatePrimitive(const U16String &str); - bool Layout(TextPrimitive *tr,const UTF16String &str); + bool Layout(TextPrimitive *tr,const U16String &str); Renderable *CreateRenderable(TextPrimitive *text_primitive); diff --git a/inc/hgl/graph/font/TileFont.h b/inc/hgl/graph/font/TileFont.h index 16fe46e5..0844388b 100644 --- a/inc/hgl/graph/font/TileFont.h +++ b/inc/hgl/graph/font/TileFont.h @@ -37,7 +37,7 @@ namespace hgl TileFont(TileData *td,FontSource *fs); virtual ~TileFont(); - bool Registry(TileUVFloatMap &,SortedSet &chars_sets); ///<注册要使用的字符 + bool Registry(TileUVFloatMap &,SortedSet &chars_sets); ///<注册要使用的字符 void Unregistry(const List &); ///<注销要使用的字符 };//class TileFont }//namespace graph diff --git a/inc/hgl/graph/mtl/Material2DCreateConfig.h b/inc/hgl/graph/mtl/Material2DCreateConfig.h index 443cac67..81f56710 100644 --- a/inc/hgl/graph/mtl/Material2DCreateConfig.h +++ b/inc/hgl/graph/mtl/Material2DCreateConfig.h @@ -6,7 +6,7 @@ #include STD_MTL_NAMESPACE_BEGIN -struct Material2DCreateConfig:public MaterialCreateConfig +struct Material2DCreateConfig:public MaterialCreateConfig,public Comparator { CoordinateSystem2D coordinate_system; ///<使用的坐标系 @@ -32,9 +32,9 @@ public: position_format=VAT_VEC2; } - int Comp(const Material2DCreateConfig &cfg)const + const int compare(const Material2DCreateConfig &cfg)const override { - int off=MaterialCreateConfig::Comp(cfg); + int off=MaterialCreateConfig::compare(cfg); if(off)return off; @@ -48,8 +48,6 @@ public: return off; } - - CompOperator(const Material2DCreateConfig &,Comp) };//struct Material2DCreateConfig:public MaterialCreateConfig MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *); diff --git a/inc/hgl/graph/mtl/Material3DCreateConfig.h b/inc/hgl/graph/mtl/Material3DCreateConfig.h index 0df9f25f..e76cbad0 100644 --- a/inc/hgl/graph/mtl/Material3DCreateConfig.h +++ b/inc/hgl/graph/mtl/Material3DCreateConfig.h @@ -5,58 +5,8 @@ #include STD_MTL_NAMESPACE_BEGIN -enum class LightingModel:uint8 -{ - Unlit, - Gizmo, /// { bool camera; ///<包含摄像机矩阵信息 @@ -82,9 +32,9 @@ public: // reverse_depth=false; } - int Comp(const Material3DCreateConfig &cfg)const + const int compare(const Material3DCreateConfig &cfg)const override { - int off=MaterialCreateConfig::Comp(cfg); + int off=MaterialCreateConfig::compare(cfg); if(off)return off; @@ -98,8 +48,6 @@ public: return off; } - - CompOperator(const Material3DCreateConfig &,Comp) };//struct Material3DCreateConfig:public MaterialCreateConfig MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *); diff --git a/inc/hgl/graph/mtl/MaterialConfig.h b/inc/hgl/graph/mtl/MaterialConfig.h index 94e32c56..5cdca42f 100644 --- a/inc/hgl/graph/mtl/MaterialConfig.h +++ b/inc/hgl/graph/mtl/MaterialConfig.h @@ -13,7 +13,7 @@ class MaterialCreateInfo; /** * 材质配置结构 */ -struct MaterialCreateConfig +struct MaterialCreateConfig:public Comparator { const GPUDeviceAttribute *dev_attr; @@ -42,7 +42,7 @@ public: prim=p; } - virtual int Comp(const MaterialCreateConfig &cfg)const + const int compare(const MaterialCreateConfig &cfg)const override { int off; @@ -59,8 +59,6 @@ public: return off; } - - CompOperator(const MaterialCreateConfig &,Comp) };//struct MaterialCreateConfig STD_MTL_NAMESPACE_END #endif//HGL_GRAPH_MTL_CONFIG_INCLUDE diff --git a/inc/hgl/graph/mtl/ShaderVariableType.h b/inc/hgl/graph/mtl/ShaderVariableType.h index d4a99b19..dfdfa478 100644 --- a/inc/hgl/graph/mtl/ShaderVariableType.h +++ b/inc/hgl/graph/mtl/ShaderVariableType.h @@ -6,551 +6,436 @@ #include #include #include -#include +#include -namespace hgl +VK_NAMESPACE_BEGIN +enum class ShaderVariableBaseType:uint8 { - namespace graph - { - enum class ShaderVariableBaseType:uint8 - { - Scalar=0, - Vector, - Matrix, - Sampler, - Image, - AtomicCounter, + Scalar=0, + Vector, + Matrix, + Sampler, + Image, + AtomicCounter, - ENUM_CLASS_RANGE(Scalar,AtomicCounter) - };//enum class ShaderVariableBaseType + ENUM_CLASS_RANGE(Scalar,AtomicCounter) +};//enum class ShaderVariableBaseType - using SVBaseType=ShaderVariableBaseType; +using SVBaseType=ShaderVariableBaseType; - #pragma pack(push,1) +#pragma pack(push,1) - struct ShaderVariableType +struct ShaderVariableType:public Comparator +{ + union + { + struct { union { struct { + SVBaseType base_type; + union { - struct + struct Scalar { - SVBaseType base_type; + VABaseType type; + }scalar; - union - { - struct Scalar - { - VABaseType type; - }scalar; + struct Vector + { + VABaseType type; + uint8 vec_size; + }vector; - struct Vector - { - VABaseType type; - uint8 vec_size; - }vector; + struct Matrix + { + VABaseType type; + uint8 n; + uint8 m; + }matrix; - struct Matrix - { - VABaseType type; - uint8 n; - uint8 m; - }matrix; + struct Sampler + { + SamplerType type; + }sampler; - struct Sampler - { - SamplerType type; - }sampler; - - struct Image - { - ShaderImageType type; - }image; - }; - }; - - uint32 type_code; + struct Image + { + ShaderImageType type; + }image; }; - - uint32 array_size; }; - uint64 svt_code; + uint32 type_code; }; - public: - - ShaderVariableType() - { - svt_code=0; - } - - ShaderVariableType(const ShaderVariableType &svt) - { - svt_code=svt.svt_code; - } - - ShaderVariableType(const VAType &vat,const uint count) - { - From(vat,count); - } - - ShaderVariableType(const VABaseType &vabt,const uint32 count) - { - svt_code=0; - - base_type=SVBaseType::Scalar; - - scalar.type=vabt; - - array_size=count; - } - - ShaderVariableType(const VABaseType &vabt,const uint8 size,const uint32 count) - { - svt_code=0; - - base_type=SVBaseType::Vector; - - vector.type=vabt; - vector.vec_size=size; - - array_size=count; - } - - ShaderVariableType(const VABaseType &vabt,const uint8 row,const uint8 col,const uint32 count) - { - svt_code=0; - - base_type=SVBaseType::Matrix; - - matrix.type=vabt; - matrix.n=col; - matrix.m=row; - - array_size=count; - } - - ShaderVariableType(const SamplerType &st,const uint32 count) - { - svt_code=0; - - base_type=SVBaseType::Sampler; - - sampler.type=st; - - array_size=count; - } - - ShaderVariableType(const ShaderImageType &sit,const uint32 count) - { - svt_code=0; - - base_type=SVBaseType::Image; - - image.type=sit; - - array_size=count; - } - - const bool Check()const - { - if(!RangeCheck(base_type))return(false); - - RANGE_CHECK_RETURN_FALSE(base_type) - - if(base_type==SVBaseType::Scalar) - return(true); - - if(base_type==SVBaseType::Vector) - { - if(vector.vec_size<2||vector.vec_size>4)return(false); - - return(true); - } - - if(base_type==SVBaseType::Matrix) - { - if(matrix.m==0) - { - if(matrix.n<2||matrix.n>4)return(false); - } - else - { - if(matrix.n<2||matrix.n>4)return(false); - if(matrix.m<2||matrix.m>4)return(false); - } - - return(true); - } - - if(base_type==SVBaseType::Sampler) - return RangeCheck(sampler.type); - - if(base_type==SVBaseType::Image) - return RangeCheck(image.type); - - return(true); - } - - int Comp(const ShaderVariableType &svt)const - { - int off=(int)base_type-(int)svt.base_type; - - if(off)return(off); - - if(base_type==SVBaseType::Scalar) - return int(scalar.type)-int(svt.scalar.type); - - if(base_type==SVBaseType::Vector) - { - off=int(vector.type)-int(svt.vector.type); - - if(off)return(off); - - off=vector.vec_size-svt.vector.vec_size; - - if(off)return(off); - - return int(vector.type)-int(svt.vector.type); - } - - if(base_type==SVBaseType::Matrix) - { - off=int(matrix.type)-int(svt.matrix.type); - - if(off)return(off); - - off=matrix.n-svt.matrix.n; - - if(off)return(off); - - return matrix.m-svt.matrix.m; - } - - if(base_type==SVBaseType::Sampler) - return int(sampler.type)-int(svt.sampler.type); - - if(base_type==SVBaseType::Image) - return int(image.type)-int(svt.image.type); - - return 0; - } - - CompOperator(const ShaderVariableType &,Comp) - - const char *GetTypename()const; - - bool ParseTypeString(const char *str); - - const uint64 ToCode()const{return svt_code;} - const bool FromCode(const uint64 code) - { - svt_code=code; - - return Check(); - } - - const bool From(const VAType &vat,const uint16 count=1) - { - array_size=count; - - if(vat.vec_size==1) - { - base_type=SVBaseType::Scalar; - scalar.type=vat.basetype; - - return(true); - } - else if(vat.vec_size<=4) - { - base_type=SVBaseType::Vector; - - vector.type=vat.basetype; - vector.vec_size=vat.vec_size; - - return(true); - } - - return(false); - } - - static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1) - { - ShaderVariableType svt; - - svt.base_type =SVBaseType::Scalar; - svt.scalar.type =vabt; - svt.array_size =count; - - return svt; - } - };//struct ShaderVariableType - #pragma pack(pop) - - using SVType=ShaderVariableType; - - const SVType SVT_BOOL (VABaseType::Bool, 1); - const SVType SVT_INT (VABaseType::Int, 1); - const SVType SVT_UINT (VABaseType::UInt, 1); - const SVType SVT_FLOAT (VABaseType::Float, 1); - const SVType SVT_DOUBLE(VABaseType::Double, 1); - - const SVType SVT_BVEC2 (VABaseType::Bool, 2,1); - const SVType SVT_BVEC3 (VABaseType::Bool, 3,1); - const SVType SVT_BVEC4 (VABaseType::Bool, 4,1); - - const SVType SVT_IVEC2 (VABaseType::Int, 2,1); - const SVType SVT_IVEC3 (VABaseType::Int, 3,1); - const SVType SVT_IVEC4 (VABaseType::Int, 4,1); - - const SVType SVT_UVEC2 (VABaseType::UInt, 2,1); - const SVType SVT_UVEC3 (VABaseType::UInt, 3,1); - const SVType SVT_UVEC4 (VABaseType::UInt, 4,1); - - const SVType SVT_VEC2 (VABaseType::Float, 2,1); - const SVType SVT_VEC3 (VABaseType::Float, 3,1); - const SVType SVT_VEC4 (VABaseType::Float, 4,1); - - const SVType SVT_DVEC2 (VABaseType::Double, 2,1); - const SVType SVT_DVEC3 (VABaseType::Double, 3,1); - const SVType SVT_DVEC4 (VABaseType::Double, 4,1); - - const SVType SVT_MAT2 (VABaseType::Float, 2,2,1); - const SVType SVT_MAT3 (VABaseType::Float, 3,3,1); - const SVType SVT_MAT4 (VABaseType::Float, 4,4,1); - const SVType SVT_MAT2x3(VABaseType::Float, 2,3,1); - const SVType SVT_MAT2x4(VABaseType::Float, 2,4,1); - const SVType SVT_MAT3x2(VABaseType::Float, 3,2,1); - const SVType SVT_MAT3x4(VABaseType::Float, 3,4,1); - const SVType SVT_MAT4x2(VABaseType::Float, 4,2,1); - const SVType SVT_MAT4x3(VABaseType::Float, 4,3,1); - - const SVType SVT_Sampler1D(SamplerType::Sampler1D, 1); - const SVType SVT_Sampler2D(SamplerType::Sampler2D, 1); - const SVType SVT_Sampler3D(SamplerType::Sampler3D, 1); - - const SVType SVT_SamplerCube(SamplerType::SamplerCube, 1); - const SVType SVT_Sampler2DRect(SamplerType::Sampler2DRect, 1); - - const SVType SVT_Sampler1DArray(SamplerType::Sampler1DArray,1); - const SVType SVT_Sampler2DArray(SamplerType::Sampler2DArray,1); - - const SVType SVT_SamplerCubeArray(SamplerType::SamplerCubeArray,1); - - const SVType SVT_SamplerBuffer(SamplerType::SamplerBuffer,1); - - const SVType SVT_Sampler2DMS(SamplerType::Sampler2DMS,1); - const SVType SVT_Sampler2DMSArray(SamplerType::Sampler2DMSArray,1); - - const SVType SVT_Sampler1DShadow(SamplerType::Sampler1DShadow,1); - const SVType SVT_Sampler2DShadow(SamplerType::Sampler2DShadow,1); - - const SVType SVT_SamplerCubeShadow(SamplerType::SamplerCubeShadow,1); - const SVType SVT_Sampler2DRectShadow(SamplerType::Sampler2DRectShadow,1); - - const SVType SVT_Sampler1DArrayShadow(SamplerType::Sampler1DArrayShadow,1); - const SVType SVT_Sampler2DArrayShadow(SamplerType::Sampler2DArrayShadow,1); - const SVType SVT_SamplerCubeArrayShadow(SamplerType::SamplerCubeArrayShadow,1); - - const SVType SVT_Image1D(ShaderImageType::Image1D,1); - const SVType SVT_Image2D(ShaderImageType::Image2D,1); - const SVType SVT_Image3D(ShaderImageType::Image3D,1); - - const SVType SVT_ImageCube(ShaderImageType::ImageCube,1); - const SVType SVT_Image2DRect(ShaderImageType::Image2DRect,1); - - const SVType SVT_Image1DArray(ShaderImageType::Image1DArray,1); - const SVType SVT_Image2DArray(ShaderImageType::Image2DArray,1); - - const SVType SVT_ImageCubeArray(ShaderImageType::ImageCubeArray,1); - - const SVType SVT_ImageBuffer(ShaderImageType::ImageBuffer,1); - - const SVType SVT_Image2DMS(ShaderImageType::Image2DMS,1); - const SVType SVT_Image2DMSArray(ShaderImageType::Image2DMSArray,1); - - struct ShaderVariable - { - char name[VERTEX_ATTRIB_NAME_MAX_LENGTH]; - uint location; - SVType type; - Interpolation interpolation; //插值方式 + uint32 array_size; }; - using SVList=List; + uint64 svt_code; + }; - struct ShaderVariableArray +public: + + ShaderVariableType() + { + svt_code=0; + } + + ShaderVariableType(const ShaderVariableType &svt) + { + svt_code=svt.svt_code; + } + + ShaderVariableType(const VAType &vat,const uint count) + { + From(vat,count); + } + + ShaderVariableType(const VABaseType &vabt,const uint32 count) + { + svt_code=0; + + base_type=SVBaseType::Scalar; + + scalar.type=vabt; + + array_size=count; + } + + ShaderVariableType(const VABaseType &vabt,const uint8 size,const uint32 count) + { + svt_code=0; + + base_type=SVBaseType::Vector; + + vector.type=vabt; + vector.vec_size=size; + + array_size=count; + } + + ShaderVariableType(const VABaseType &vabt,const uint8 row,const uint8 col,const uint32 count) + { + svt_code=0; + + base_type=SVBaseType::Matrix; + + matrix.type=vabt; + matrix.n=col; + matrix.m=row; + + array_size=count; + } + + ShaderVariableType(const SamplerType &st,const uint32 count) + { + svt_code=0; + + base_type=SVBaseType::Sampler; + + sampler.type=st; + + array_size=count; + } + + ShaderVariableType(const ShaderImageType &sit,const uint32 count) + { + svt_code=0; + + base_type=SVBaseType::Image; + + image.type=sit; + + array_size=count; + } + + const bool Check()const; + + const int compare(const ShaderVariableType &svt)const override; + + const char *GetTypename()const; + + bool ParseTypeString(const char *str); + + const uint64 ToCode()const{return svt_code;} + const bool FromCode(const uint64 code) + { + svt_code=code; + + return Check(); + } + + const bool From(const VAType &vat,const uint16 count=1); + + static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1) + { + ShaderVariableType svt; + + svt.base_type =SVBaseType::Scalar; + svt.scalar.type =vabt; + svt.array_size =count; + + return svt; + } +};//struct ShaderVariableType +#pragma pack(pop) + +using SVType=ShaderVariableType; + +const SVType SVT_BOOL (VABaseType::Bool, 1); +const SVType SVT_INT (VABaseType::Int, 1); +const SVType SVT_UINT (VABaseType::UInt, 1); +const SVType SVT_FLOAT (VABaseType::Float, 1); +const SVType SVT_DOUBLE(VABaseType::Double, 1); + +const SVType SVT_BVEC2 (VABaseType::Bool, 2,1); +const SVType SVT_BVEC3 (VABaseType::Bool, 3,1); +const SVType SVT_BVEC4 (VABaseType::Bool, 4,1); + +const SVType SVT_IVEC2 (VABaseType::Int, 2,1); +const SVType SVT_IVEC3 (VABaseType::Int, 3,1); +const SVType SVT_IVEC4 (VABaseType::Int, 4,1); + +const SVType SVT_UVEC2 (VABaseType::UInt, 2,1); +const SVType SVT_UVEC3 (VABaseType::UInt, 3,1); +const SVType SVT_UVEC4 (VABaseType::UInt, 4,1); + +const SVType SVT_VEC2 (VABaseType::Float, 2,1); +const SVType SVT_VEC3 (VABaseType::Float, 3,1); +const SVType SVT_VEC4 (VABaseType::Float, 4,1); + +const SVType SVT_DVEC2 (VABaseType::Double, 2,1); +const SVType SVT_DVEC3 (VABaseType::Double, 3,1); +const SVType SVT_DVEC4 (VABaseType::Double, 4,1); + +const SVType SVT_MAT2 (VABaseType::Float, 2,2,1); +const SVType SVT_MAT3 (VABaseType::Float, 3,3,1); +const SVType SVT_MAT4 (VABaseType::Float, 4,4,1); +const SVType SVT_MAT2x3(VABaseType::Float, 2,3,1); +const SVType SVT_MAT2x4(VABaseType::Float, 2,4,1); +const SVType SVT_MAT3x2(VABaseType::Float, 3,2,1); +const SVType SVT_MAT3x4(VABaseType::Float, 3,4,1); +const SVType SVT_MAT4x2(VABaseType::Float, 4,2,1); +const SVType SVT_MAT4x3(VABaseType::Float, 4,3,1); + +const SVType SVT_Sampler1D(SamplerType::Sampler1D, 1); +const SVType SVT_Sampler2D(SamplerType::Sampler2D, 1); +const SVType SVT_Sampler3D(SamplerType::Sampler3D, 1); + +const SVType SVT_SamplerCube(SamplerType::SamplerCube, 1); +const SVType SVT_Sampler2DRect(SamplerType::Sampler2DRect, 1); + +const SVType SVT_Sampler1DArray(SamplerType::Sampler1DArray,1); +const SVType SVT_Sampler2DArray(SamplerType::Sampler2DArray,1); + +const SVType SVT_SamplerCubeArray(SamplerType::SamplerCubeArray,1); + +const SVType SVT_SamplerBuffer(SamplerType::SamplerBuffer,1); + +const SVType SVT_Sampler2DMS(SamplerType::Sampler2DMS,1); +const SVType SVT_Sampler2DMSArray(SamplerType::Sampler2DMSArray,1); + +const SVType SVT_Sampler1DShadow(SamplerType::Sampler1DShadow,1); +const SVType SVT_Sampler2DShadow(SamplerType::Sampler2DShadow,1); + +const SVType SVT_SamplerCubeShadow(SamplerType::SamplerCubeShadow,1); +const SVType SVT_Sampler2DRectShadow(SamplerType::Sampler2DRectShadow,1); + +const SVType SVT_Sampler1DArrayShadow(SamplerType::Sampler1DArrayShadow,1); +const SVType SVT_Sampler2DArrayShadow(SamplerType::Sampler2DArrayShadow,1); +const SVType SVT_SamplerCubeArrayShadow(SamplerType::SamplerCubeArrayShadow,1); + +const SVType SVT_Image1D(ShaderImageType::Image1D,1); +const SVType SVT_Image2D(ShaderImageType::Image2D,1); +const SVType SVT_Image3D(ShaderImageType::Image3D,1); + +const SVType SVT_ImageCube(ShaderImageType::ImageCube,1); +const SVType SVT_Image2DRect(ShaderImageType::Image2DRect,1); + +const SVType SVT_Image1DArray(ShaderImageType::Image1DArray,1); +const SVType SVT_Image2DArray(ShaderImageType::Image2DArray,1); + +const SVType SVT_ImageCubeArray(ShaderImageType::ImageCubeArray,1); + +const SVType SVT_ImageBuffer(ShaderImageType::ImageBuffer,1); + +const SVType SVT_Image2DMS(ShaderImageType::Image2DMS,1); +const SVType SVT_Image2DMSArray(ShaderImageType::Image2DMSArray,1); + +struct ShaderVariable +{ + char name[VERTEX_ATTRIB_NAME_MAX_LENGTH]; + uint location; + SVType type; + Interpolation interpolation; //插值方式 +}; + +using SVList=List; + +struct ShaderVariableArray:public Comparator +{ + uint count; + + ShaderVariable *items; + +public: + + const bool IsEmpty()const{return !items||count<=0;} + +public: + + ShaderVariableArray() + { + count=0; + items=nullptr; + } + + ~ShaderVariableArray() + { + Clear(); + } + + const int compare(const ShaderVariableArray &sva)const override + { + int off=count-sva.count; + if(off)return off; + + for(uint i=0;isva.items[i].type.ToCode()) + return 1; - public: + //ToCode返回的是uint64,可能差值超大,所以不能直接用-的结果 - const bool IsEmpty()const{return !items||count<=0;} + if(items[i].type.ToCode()count; - if(off)return off; - - for(uint i=0;iitems[i].location; - if(off) - return off; - - if(items[i].type.ToCode()>sva->items[i].type.ToCode()) - return 1; - - //ToCode返回的是uint64,可能差值超大,所以不能直接用-的结果 - - if(items[i].type.ToCode()items[i].type.ToCode()) - return -1; - - off=int(items[i].interpolation)-int(sva->items[i].interpolation); - if(off) - return off; - - off=hgl::strcmp(items[i].name,sva->items[i].name); - if(off) - return off; - } - - return 0; - } - - int Comp(const ShaderVariableArray &sva)const{return Comp(&sva);} - - CompOperator(const ShaderVariableArray *,Comp) - CompOperator(const ShaderVariableArray &,Comp) + return 0; + } - bool Init(const uint c=0) - { - if(items) - return(false); + bool Init(const uint c=0) + { + if(items) + return(false); - if(c>0) - { - count=c; - items=array_alloc(count); - } - else - { - count=0; - items=nullptr; - } + if(c>0) + { + count=c; + items=array_alloc(count); + } + else + { + count=0; + items=nullptr; + } + return(true); + } + + bool Contains(const char *name)const + { + if(count<=0) + return(false); + + for(uint i=0;i(1); - count=1; - } - else - { - ++count; - items=array_realloc(items,count); - } + if(!items) + { + items=array_alloc(1); + count=1; + } + else + { + ++count; + items=array_realloc(items,count); + } - hgl_cpy(items[count-1],sv); - return(true); - } + hgl_cpy(items[count-1],sv); + return(true); + } - void Clear() - { - if(items) - { - array_free(items); - items=nullptr; - } + void Clear() + { + if(items) + { + array_free(items); + items=nullptr; + } - count=0; - } + count=0; + } - bool Clone(const ShaderVariableArray *src) - { - if(!src) - return(false); + bool Clone(const ShaderVariableArray *src) + { + if(!src) + return(false); - if(!Init(src->count)) - return(false); + if(!Init(src->count)) + return(false); - hgl_cpy(items,src->items,src->count); - return(true); - } + hgl_cpy(items,src->items,src->count); + return(true); + } - void ToString(AnsiString &output_string) + void ToString(AnsiString &output_string) + { + if(IsEmpty()) + return; + + const ShaderVariable *sv=items; + + for(uint i=0;iinterpolation!=Interpolation::Smooth) { - if(IsEmpty()) - return; - - const ShaderVariable *sv=items; - - for(uint i=0;iinterpolation)) { - output_string+=" "; - - if(sv->interpolation!=Interpolation::Smooth) - { - if(RangeCheck(sv->interpolation)) - { - output_string+=InterpolationName[size_t(sv->interpolation)]; - output_string+=" "; - } - } - - output_string+=sv->type.GetTypename(); + output_string+=InterpolationName[size_t(sv->interpolation)]; output_string+=" "; - output_string+=sv->name; - output_string+=";\n"; - - ++sv; } } - };//struct ShaderVariableArray - using SVArray=ShaderVariableArray; - }//namespace graph -}//namespace hgl + output_string+=sv->type.GetTypename(); + output_string+=" "; + output_string+=sv->name; + output_string+=";\n"; + + ++sv; + } + } +};//struct ShaderVariableArray + +using SVArray=ShaderVariableArray; + +VK_NAMESPACE_END diff --git a/inc/hgl/shadergen/ShaderCreateInfo.h b/inc/hgl/shadergen/ShaderCreateInfo.h index 215495d7..d5f530a1 100644 --- a/inc/hgl/shadergen/ShaderCreateInfo.h +++ b/inc/hgl/shadergen/ShaderCreateInfo.h @@ -96,7 +96,7 @@ public: void SetMain(const AnsiString &str){main_function=str;} void SetMain(const char *str,const int len) { - main_function.SetString(str,len); + main_function.fromString(str,len); } const AnsiString &GetOutputStruct()const{return output_struct;} diff --git a/src/SceneGraph/MaterialRenderList.cpp b/src/SceneGraph/MaterialRenderList.cpp index 757578e5..4aee43b8 100644 --- a/src/SceneGraph/MaterialRenderList.cpp +++ b/src/SceneGraph/MaterialRenderList.cpp @@ -26,22 +26,13 @@ 这样就可以保证所有的渲染操作就算要切VBO,也不需要切换INDIRECT缓冲区,定位指令也很方便。 */ -template<> -int Comparator::compare(const hgl::graph::RenderNode &obj_one,const hgl::graph::RenderNode &obj_two) const +VK_NAMESPACE_BEGIN +const int RenderNode::compare(const RenderNode &other)const { hgl::int64 off; - hgl::graph::Renderable *ri_one=obj_one.scene_node->GetRenderable(); - hgl::graph::Renderable *ri_two=obj_two.scene_node->GetRenderable(); - - //比较管线 - { - off=ri_one->GetPipeline() - -ri_two->GetPipeline(); - - if(off) - return off; - } + hgl::graph::Renderable *ri_one=other.scene_node->GetRenderable(); + hgl::graph::Renderable *ri_two=scene_node->GetRenderable(); auto *prim_one=ri_one->GetPrimitive(); auto *prim_two=ri_two->GetPrimitive(); @@ -72,8 +63,8 @@ int Comparator::compare(const hgl::graph::RenderNode &ob //比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释 - float foff=obj_one.to_camera_distance - -obj_two.to_camera_distance; + float foff=other.to_camera_distance + -to_camera_distance; if(foff>0) return 1; @@ -81,18 +72,17 @@ int Comparator::compare(const hgl::graph::RenderNode &ob return -1; } -VK_NAMESPACE_BEGIN -MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,Material *m) +MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi) { device=d; cmd_buf=nullptr; - material=m; + rp_index=rpi; camera_info=nullptr; - assign_buffer=new RenderAssignBuffer(device,material); + assign_buffer=new RenderAssignBuffer(device,rp_index.material); - vab_list=new VABList(material->GetVertexInput()->GetCount()); + vab_list=new VABList(rp_index.material->GetVertexInput()->GetCount()); icb_draw=nullptr; icb_draw_indexed=nullptr; @@ -215,7 +205,6 @@ void MaterialRenderList::UpdateMaterialInstance(SceneNode *sn) void MaterialRenderList::RenderItem::Set(Renderable *ri) { - pipeline=ri->GetPipeline(); mi =ri->GetMaterialInstance(); pdb =ri->GetDataBuffer(); prd =ri->GetRenderData(); @@ -248,6 +237,7 @@ void MaterialRenderList::WriteICB(VkDrawIndirectCommand *dicp,RenderItem *ri) dicp->firstVertex =ri->prd->vertex_offset; dicp->firstInstance =ri->first_instance; } + void MaterialRenderList::WriteICB(VkDrawIndexedIndirectCommand *diicp,RenderItem *ri) { diicp->indexCount =ri->prd->index_count; @@ -279,7 +269,6 @@ void MaterialRenderList::Stat() ri->instance_count=1; ri->Set(ro); - last_pipeline =ri->pipeline; last_data_buffer=ri->pdb; last_vdm =ri->pdb->vdm; last_render_data=ri->prd; @@ -290,14 +279,13 @@ void MaterialRenderList::Stat() { ro=rn->scene_node->GetRenderable(); - if(last_pipeline==ro->GetPipeline()) - if(last_data_buffer->Comp(ro->GetDataBuffer())) - if(last_render_data->_Comp(ro->GetRenderData())==0) - { - ++ri->instance_count; - ++rn; - continue; - } + if(*last_data_buffer!=*ro->GetDataBuffer()) + if(*last_render_data==*ro->GetRenderData()) + { + ++ri->instance_count; + ++rn; + continue; + } if(ri->pdb->vdm) { @@ -317,7 +305,6 @@ void MaterialRenderList::Stat() ri->instance_count=1; ri->Set(ro); - last_pipeline =ri->pipeline; last_data_buffer=ri->pdb; last_vdm =ri->pdb->vdm; last_render_data=ri->prd; @@ -411,17 +398,7 @@ void MaterialRenderList::ProcIndirectRender() void MaterialRenderList::Render(RenderItem *ri) { - if(last_pipeline!=ri->pipeline) - { - cmd_buf->BindPipeline(ri->pipeline); - last_pipeline=ri->pipeline; - - last_data_buffer=nullptr; - - //这里未来尝试换pipeline同时不换mi/primitive是否需要重新绑定mi/primitive - } - - if(!ri->pdb->Comp(last_data_buffer)) //换buf了 + if(*(ri->pdb)!=*last_data_buffer) //换buf了 { if(indirect_draw_count) //如果有间接绘制的数据,赶紧给画了 ProcIndirectRender(); @@ -432,7 +409,7 @@ void MaterialRenderList::Render(RenderItem *ri) BindVAB(ri->pdb,ri->first_instance); if(ri->pdb->ibo) - cmd_buf->BindIBO(ri->pdb->ibo); + cmd_buf->BindIBO(ri->pdb->ibo); } if(ri->pdb->vdm) @@ -459,15 +436,16 @@ void MaterialRenderList::Render(RenderCmdBuffer *rcb) cmd_buf=rcb; - last_pipeline =nullptr; + cmd_buf->BindPipeline(rp_index.pipeline); + last_data_buffer=nullptr; last_vdm =nullptr; last_render_data=nullptr; if(assign_buffer) - assign_buffer->Bind(material); + assign_buffer->Bind(rp_index.material); - cmd_buf->BindDescriptorSets(material); + cmd_buf->BindDescriptorSets(rp_index.material); RenderItem *ri=ri_array.GetData(); for(uint i=0;iGetMaterial(); + RenderPipelineIndex rpi(ri->GetMaterial(),ri->GetPipeline()); + MaterialRenderList *mrl; - if(!mrl_map.Get(mtl,mrl)) + if(!mrl_map.Get(rpi,mrl)) { - mrl=new MaterialRenderList(device,true,mtl); + mrl=new MaterialRenderList(device,true,rpi); - mrl_map.Add(mtl,mrl); + mrl_map.Add(rpi,mrl); } mrl->Add(sn); @@ -92,10 +93,10 @@ namespace hgl if(!ri)return; - Material *mtl=ri->GetMaterial(); + RenderPipelineIndex rli(ri->GetMaterial(),ri->GetPipeline()); MaterialRenderList *mrl; - if(!mrl_map.Get(mtl,mrl)) //找到对应的 + if(!mrl_map.Get(rli,mrl)) //找到对应的 return; mrl->UpdateMaterialInstance(sn); diff --git a/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp b/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp index bb42f89a..bbd4ba72 100644 --- a/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp @@ -48,9 +48,9 @@ MaterialParameters *GPUDevice::CreateMP(const MaterialDescriptorManager *desc_ma if(!ds)return(nullptr); #ifdef _DEBUG - const UTF8String addr_string=HexToString((uint64_t)(ds->GetDescriptorSet())); + const U8String addr_string=HexToString((uint64_t)(ds->GetDescriptorSet())); - LOG_INFO(U8_TEXT("Create [DescriptSets:")+addr_string+U8_TEXT("] OK! Material Name: \"")+(const UTF8String &)(desc_manager->GetMaterialName())+U8_TEXT("\" Type: ")+(u8char *)(GetDescriptorSetTypeName(desc_set_type))); + LOG_INFO(U8_TEXT("Create [DescriptSets:")+addr_string+U8_TEXT("] OK! Material Name: \"")+(const U8String &)(desc_manager->GetMaterialName())+U8_TEXT("\" Type: ")+(u8char *)(GetDescriptorSetTypeName(desc_set_type))); #endif//_DEBUG return(new MaterialParameters(desc_manager,desc_set_type,ds)); diff --git a/src/SceneGraph/Vulkan/VKDeviceRenderPassManage.cpp b/src/SceneGraph/Vulkan/VKDeviceRenderPassManage.cpp index b2a44524..4980daa5 100644 --- a/src/SceneGraph/Vulkan/VKDeviceRenderPassManage.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceRenderPassManage.cpp @@ -188,8 +188,8 @@ DeviceRenderPassManage::DeviceRenderPassManage(VkDevice dev,VkPipelineCache pc) { device=dev; pipeline_cache=pc; - - hash=util::CreateSHA1LEHash(); + + hash=CreateRenderPassHash(); } DeviceRenderPassManage::~DeviceRenderPassManage() @@ -250,8 +250,8 @@ namespace // } void HashRenderPass(RenderPassHASHCode *code,const RenderbufferInfo *rbi,const uint8 subpass_count) - { - util::Hash *hash=util::CreateSHA1LEHash(); + { + util::Hash *hash=CreateRenderPassHash(); hash->Init(); diff --git a/src/SceneGraph/Vulkan/VKRenderResource.cpp b/src/SceneGraph/Vulkan/VKRenderResource.cpp index ec89022a..a0499def 100644 --- a/src/SceneGraph/Vulkan/VKRenderResource.cpp +++ b/src/SceneGraph/Vulkan/VKRenderResource.cpp @@ -158,7 +158,7 @@ Texture2D *RenderResource::LoadTexture2D(const OSString &filename,bool auto_mipm if(du) { - const UTF8String name=U8_TEXT("Tex2D:")+ToUTF8String(filename); + const U8String name=U8_TEXT("Tex2D:")+ToU8String(filename); du->SetImage(tex->GetImage(),(char *)(name.c_str())); } diff --git a/src/SceneGraph/Vulkan/VKRenderable.cpp b/src/SceneGraph/Vulkan/VKRenderable.cpp index 24402039..0ed3831c 100644 --- a/src/SceneGraph/Vulkan/VKRenderable.cpp +++ b/src/SceneGraph/Vulkan/VKRenderable.cpp @@ -24,25 +24,29 @@ PrimitiveDataBuffer::~PrimitiveDataBuffer() delete[] vab_list; } -const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *pdb)const +const int PrimitiveDataBuffer::compare(const PrimitiveDataBuffer &pdb)const { - if(!pdb)return(false); + ptrdiff_t off; - if(vdm&&pdb->vdm) - return (vdm==pdb->vdm); + off=&vdm-&pdb.vdm; + if(off) + return off; - if(vab_count!=pdb->vab_count)return(false); + off=vab_count-pdb.vab_count; + if(off) + return off; - for(uint32_t i=0;ivab_list[i])return(false); - if(vab_offset[i]!=pdb->vab_offset[i])return(false); - } + off=hgl_cmp(vab_list,pdb.vab_list,vab_count); + if(off) + return off; - if(ibo!=pdb->ibo) - return(false); + off=hgl_cmp(vab_offset,pdb.vab_offset,vab_count); + if(off) + return off; - return(true); + off=ibo-pdb.ibo; + + return off; } Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *pdb,PrimitiveRenderData *prd) @@ -61,7 +65,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) const VIL *vil=mi->GetVIL(); - if(vil->Comp(p->GetVIL())) + if(*vil!=*p->GetVIL()) return(nullptr); const uint32_t input_count=vil->GetVertexAttribCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的 diff --git a/src/ShaderGen/ShaderLibrary.cpp b/src/ShaderGen/ShaderLibrary.cpp index 1dbe02fb..8fffd0cc 100644 --- a/src/ShaderGen/ShaderLibrary.cpp +++ b/src/ShaderGen/ShaderLibrary.cpp @@ -35,7 +35,7 @@ const AnsiString *LoadShader(const AnsiString &shader_name) shader=new AnsiString; - if(LoadStringFromTextFile((UTF8String &)*shader,os_fn)<=0) + if(LoadStringFromTextFile((U8String &)*shader,os_fn)<=0) { delete shader; shader=nullptr; diff --git a/src/ShaderGen/ShaderVariableType.cpp b/src/ShaderGen/ShaderVariableType.cpp index 49abfe95..2d5a381f 100644 --- a/src/ShaderGen/ShaderVariableType.cpp +++ b/src/ShaderGen/ShaderVariableType.cpp @@ -45,6 +45,90 @@ namespace constexpr const char AtomicCounterTypename[]="atomic_uint"; }//namespace +const bool ShaderVariableType::Check()const +{ + if(!RangeCheck(base_type))return(false); + + RANGE_CHECK_RETURN_FALSE(base_type) + + if(base_type==SVBaseType::Scalar) + return(true); + + if(base_type==SVBaseType::Vector) + { + if(vector.vec_size<2||vector.vec_size>4)return(false); + + return(true); + } + + if(base_type==SVBaseType::Matrix) + { + if(matrix.m==0) + { + if(matrix.n<2||matrix.n>4)return(false); + } + else + { + if(matrix.n<2||matrix.n>4)return(false); + if(matrix.m<2||matrix.m>4)return(false); + } + + return(true); + } + + if(base_type==SVBaseType::Sampler) + return RangeCheck(sampler.type); + + if(base_type==SVBaseType::Image) + return RangeCheck(image.type); + + return(true); +} + +const int ShaderVariableType::compare(const ShaderVariableType &svt)const +{ + int off=(int)base_type-(int)svt.base_type; + + if(off)return(off); + + if(base_type==SVBaseType::Scalar) + return int(scalar.type)-int(svt.scalar.type); + + if(base_type==SVBaseType::Vector) + { + off=int(vector.type)-int(svt.vector.type); + + if(off)return(off); + + off=vector.vec_size-svt.vector.vec_size; + + if(off)return(off); + + return int(vector.type)-int(svt.vector.type); + } + + if(base_type==SVBaseType::Matrix) + { + off=int(matrix.type)-int(svt.matrix.type); + + if(off)return(off); + + off=matrix.n-svt.matrix.n; + + if(off)return(off); + + return matrix.m-svt.matrix.m; + } + + if(base_type==SVBaseType::Sampler) + return int(sampler.type)-int(svt.sampler.type); + + if(base_type==SVBaseType::Image) + return int(image.type)-int(svt.image.type); + + return 0; +} + const char *ShaderVariableType::GetTypename()const { if(base_type==SVBaseType::Scalar) @@ -268,4 +352,28 @@ bool ShaderVariableType::ParseTypeString(const char *str) return(false); } + +const bool ShaderVariableType::From(const VAType &vat,const uint16 count) +{ + array_size=count; + + if(vat.vec_size==1) + { + base_type=SVBaseType::Scalar; + scalar.type=vat.basetype; + + return(true); + } + else if(vat.vec_size<=4) + { + base_type=SVBaseType::Vector; + + vector.type=vat.basetype; + vector.vec_size=vat.vec_size; + + return(true); + } + + return(false); +} VK_NAMESPACE_END