Merge branch 'master' of https://github.com/hyzboy/ULRE
This commit is contained in:
@@ -8,30 +8,31 @@
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
|
||||
/**
|
||||
* 渲染对象列表<br>
|
||||
* 已经展开的渲染对象列表,产生mvp用UBO/SSBO等数据,最终创建RenderCommandBuffer
|
||||
*/
|
||||
class RenderList
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
GPUDevice * device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
GPUDevice * device;
|
||||
RenderCmdBuffer * cmd_buf;
|
||||
|
||||
private:
|
||||
|
||||
RenderNodeList render_node_list; ///<场景节点列表
|
||||
MaterialSets material_sets; ///<材质合集
|
||||
GPUArrayBuffer * mvp_array;
|
||||
CameraInfo camera_info;
|
||||
|
||||
RenderNodeComparator *render_node_comparator;
|
||||
RenderNode3DList render_node_list; ///<场景节点列表
|
||||
MaterialSets material_sets; ///<材质合集
|
||||
|
||||
RenderNode3DComparator *render_node_comparator;
|
||||
|
||||
private:
|
||||
|
||||
@@ -61,49 +62,11 @@ namespace hgl
|
||||
|
||||
RenderList(GPUDevice *);
|
||||
virtual ~RenderList();
|
||||
|
||||
|
||||
virtual bool Expend(const CameraInfo &,SceneNode *);
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *);
|
||||
};//class RenderList
|
||||
|
||||
class RenderList2D:public RenderList
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool Begin() override;
|
||||
virtual bool Expend(SceneNode *) override;
|
||||
virtual void End() override;
|
||||
|
||||
public:
|
||||
|
||||
RenderList2D();
|
||||
virtual ~RenderList2D() override;
|
||||
|
||||
virtual bool Expend(SceneNode *);
|
||||
};
|
||||
|
||||
class RenderList3D:public RenderList
|
||||
{
|
||||
protected:
|
||||
|
||||
CameraInfo camera_info;
|
||||
GPUArrayBuffer *mvp_array;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool Begin() override;
|
||||
virtual bool Expend(SceneNode *) override;
|
||||
virtual void End() override;
|
||||
|
||||
public:
|
||||
|
||||
RenderList3D();
|
||||
virtual ~RenderList3D() override;
|
||||
|
||||
bool Expend(const CameraInfo &,SceneNode *);
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
|
@@ -1,37 +1,34 @@
|
||||
#ifndef HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
#ifndef HGL_GRAPH_RENDER_LIST_2D_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_LIST_2D_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/RenderNode2D.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
|
||||
/**
|
||||
* 渲染对象列表<br>
|
||||
* 已经展开的渲染对象列表,产生mvp用UBO/SSBO等数据,最终创建RenderCommandBuffer
|
||||
*/
|
||||
class RenderList
|
||||
class RenderList2D
|
||||
{
|
||||
protected:
|
||||
|
||||
GPUDevice * device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
GPUDevice * device;
|
||||
RenderCmdBuffer * cmd_buf;
|
||||
|
||||
private:
|
||||
|
||||
RenderNodeList render_node_list; ///<场景节点列表
|
||||
MaterialSets material_sets; ///<材质合集
|
||||
// GPUArrayBuffer * mvp_array;
|
||||
|
||||
RenderNodeComparator *render_node_comparator;
|
||||
RenderNode2DList render_node_list; ///<场景节点列表
|
||||
MaterialSets material_sets; ///<材质合集
|
||||
|
||||
RenderNode2DComparator render_node_comparator;
|
||||
|
||||
private:
|
||||
|
||||
@@ -46,7 +43,7 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
virtual bool Begin();
|
||||
virtual bool Expend(SceneNode *);
|
||||
virtual bool ExpendNode(SceneNode *);
|
||||
virtual void End();
|
||||
|
||||
private:
|
||||
@@ -59,51 +56,13 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
RenderList(GPUDevice *);
|
||||
virtual ~RenderList();
|
||||
RenderList2D(GPUDevice *);
|
||||
virtual ~RenderList2D();
|
||||
|
||||
virtual bool Expend(const CameraInfo &,SceneNode *);
|
||||
virtual bool Expend(SceneNode *);
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *);
|
||||
};//class RenderList
|
||||
|
||||
class RenderList2D:public RenderList
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool Begin() override;
|
||||
virtual bool Expend(SceneNode *) override;
|
||||
virtual void End() override;
|
||||
|
||||
public:
|
||||
|
||||
RenderList2D();
|
||||
virtual ~RenderList2D() override;
|
||||
|
||||
virtual bool Expend(SceneNode *);
|
||||
};
|
||||
|
||||
class RenderList3D:public RenderList
|
||||
{
|
||||
protected:
|
||||
|
||||
CameraInfo camera_info;
|
||||
GPUArrayBuffer *mvp_array;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool Begin() override;
|
||||
virtual bool Expend(SceneNode *) override;
|
||||
virtual void End() override;
|
||||
|
||||
public:
|
||||
|
||||
RenderList3D();
|
||||
virtual ~RenderList3D() override;
|
||||
|
||||
bool Expend(const CameraInfo &,SceneNode *);
|
||||
};
|
||||
};//class RenderList2D
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_LIST_INCLUDE
|
||||
#endif//HGL_GRAPH_RENDER_LIST_2D_INCLUDE
|
||||
|
@@ -1,30 +1,16 @@
|
||||
#ifndef HGL_GRAPH_RENDER_NODE_2D_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_NODE_2D_INCLUDE
|
||||
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/math/Math.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Renderable;
|
||||
|
||||
struct Transiton2D
|
||||
{
|
||||
Vector2f move;
|
||||
Vector2f center; //中心点
|
||||
|
||||
//下方的不管是缩放还是旋转,均以上面的center为中心变换
|
||||
|
||||
Vector2f scale;
|
||||
float rotate;
|
||||
float z;
|
||||
};
|
||||
|
||||
struct RenderNode2D
|
||||
{
|
||||
Transiton2D trans;
|
||||
Matrix3x4f local_to_world;
|
||||
|
||||
Renderable *ri;
|
||||
};
|
||||
|
@@ -1,14 +1,15 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKMemoryAllocator.h>
|
||||
#include<hgl/type/Collection.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
namespace hgl
|
||||
{
|
||||
class Collection;
|
||||
|
||||
namespace graph
|
||||
{
|
||||
class VKMemoryAllocator;
|
||||
|
||||
/**
|
||||
* GPU数据阵列缓冲区<br>
|
||||
* 它用于储存多份相同格式的数据,常用于多物件渲染,instance等
|
||||
@@ -24,72 +25,24 @@ namespace hgl
|
||||
|
||||
VKMemoryAllocator *vk_ma;
|
||||
|
||||
uint32_t ubo_offset_alignment;
|
||||
uint32_t offset_alignment;
|
||||
|
||||
Collection *coll;
|
||||
|
||||
public:
|
||||
|
||||
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il)
|
||||
{
|
||||
device=dev;
|
||||
buffer_usage_flags=flags;
|
||||
item_length=il;
|
||||
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il,VkDescriptorType dt);
|
||||
virtual ~GPUArrayBuffer();
|
||||
|
||||
{
|
||||
ubo_offset_alignment=device->GetUBOAlign();
|
||||
const uint32_t GetOffsetAlignment()const{return offset_alignment;}
|
||||
const uint32_t GetUnitSize()const;
|
||||
DeviceBuffer * GetBuffer();
|
||||
|
||||
const uint32_t unit_size=hgl_align<uint32_t>(item_length,ubo_offset_alignment);
|
||||
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
||||
void Clear();
|
||||
|
||||
vk_ma=new VKMemoryAllocator(device,buffer_usage_flags,unit_size); // construct function is going to set AllocUnitSize by minUniformOffsetAlignment
|
||||
MemoryBlock *mb=new MemoryBlock(vk_ma);
|
||||
|
||||
coll=new Collection(unit_size,mb);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~GPUArrayBuffer()
|
||||
{
|
||||
delete coll;
|
||||
}
|
||||
|
||||
const uint32_t GetOffsetAlignment()const
|
||||
{
|
||||
return ubo_offset_alignment;
|
||||
}
|
||||
|
||||
const uint32_t GetUnitSize()const
|
||||
{
|
||||
return coll->GetUnitBytes();
|
||||
}
|
||||
|
||||
DeviceBuffer *GetBuffer()
|
||||
{
|
||||
return vk_ma->GetBuffer();
|
||||
}
|
||||
|
||||
uint32 Alloc(const uint32 max_count) ///<预分配空间
|
||||
{
|
||||
if(!coll->Alloc(max_count))
|
||||
return(0);
|
||||
|
||||
return coll->GetAllocCount();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
coll->Clear();
|
||||
}
|
||||
|
||||
void *Map(const uint32 start,const uint32 count)
|
||||
{
|
||||
return coll->Map(start,count);
|
||||
}
|
||||
|
||||
void Flush(const uint32 count)
|
||||
{
|
||||
vk_ma->Flush(count*GetUnitSize());
|
||||
}
|
||||
void * Map(const uint32 start,const uint32 count);
|
||||
void Flush(const uint32 count);
|
||||
};//class GPUArrayBuffer
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
91
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
91
inc/hgl/graph/VKDescriptorBindingManage.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class MaterialParameters;
|
||||
|
||||
class DescriptorBinding
|
||||
{
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
Map<AnsiString,Texture *> texture_map;
|
||||
|
||||
public:
|
||||
|
||||
bool AddUBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ubo_map,name);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ubo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddSSBO(const AnsiString &name,DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ssbo_map,name);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
{
|
||||
if(!buf)return;
|
||||
|
||||
ssbo_map.DeleteByValue(buf);
|
||||
}
|
||||
|
||||
bool AddTexture(const AnsiString &name,Texture *tex)
|
||||
{
|
||||
if(!tex)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
return texture_map.Add(name,tex);
|
||||
}
|
||||
|
||||
Texture *GetTexture(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(texture_map,name);
|
||||
}
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
{
|
||||
if(!tex)return;
|
||||
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
bool Bind(MaterialParameters *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
@@ -135,6 +135,7 @@ public: //Buffer相关
|
||||
IndexBuffer * CreateIBO32 ( uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,nullptr,sm);}
|
||||
|
||||
const VkDeviceSize GetUBOAlign();
|
||||
const VkDeviceSize GetSSBOAlign();
|
||||
|
||||
#define CREATE_BUFFER_OBJECT(LargeName,type) DeviceBuffer *Create##LargeName( VkDeviceSize size,void *data, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,data, sm);} \
|
||||
DeviceBuffer *Create##LargeName( VkDeviceSize size, SharingMode sm=SharingMode::Exclusive) {return CreateBuffer(VK_BUFFER_USAGE_##type##_BUFFER_BIT,size ,size,nullptr, sm);} \
|
||||
|
@@ -78,5 +78,7 @@ public:
|
||||
bool Release(VIL *);
|
||||
const uint GetVILCount();
|
||||
};//class Material
|
||||
|
||||
using MaterialSets=SortedSets<Material *>;
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
@@ -5,11 +5,14 @@
|
||||
#include<hgl/graph/VKShaderDescriptorSet.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using BindingMap=Map<AnsiString,int>;
|
||||
using BindingMapArray=BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class MaterialDescriptorManager
|
||||
{
|
||||
UTF8String mtl_name;
|
||||
|
||||
Map<AnsiString,int> binding_map[DESCRIPTOR_SET_TYPE_COUNT][VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
BindingMapArray binding_map[DESCRIPTOR_SET_TYPE_COUNT];
|
||||
|
||||
private:
|
||||
|
||||
@@ -32,6 +35,11 @@ public:
|
||||
return dsl_ci[size_t(set_type)].bindingCount;
|
||||
}
|
||||
|
||||
const BindingMapArray &GetBindingMap(const DescriptorSetType &set_type)const
|
||||
{
|
||||
return binding_map[size_t(set_type)];
|
||||
}
|
||||
|
||||
const int GetBinding(const DescriptorSetType &set_type,const VkDescriptorType &desc_type,const AnsiString &name)const;
|
||||
|
||||
const int GetUBO (const DescriptorSetType &set_type,const AnsiString &name,bool dynamic)const{return GetBinding(set_type,dynamic?VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,name);}
|
||||
|
@@ -31,6 +31,7 @@ public:
|
||||
const VkDescriptorSet GetVkDescriptorSet ()const{return descriptor_set->GetDescriptorSet();}
|
||||
|
||||
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
|
||||
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
|
||||
|
||||
const uint32_t GetDynamicCount ()const //返回动态ubo/ssbo总量
|
||||
{
|
||||
@@ -43,7 +44,6 @@ public:
|
||||
public:
|
||||
|
||||
#define MP_TYPE_IS(name) const bool is##name()const{return set_type==DescriptorSetType::name;}
|
||||
MP_TYPE_IS(Skeleton)
|
||||
MP_TYPE_IS(Instance)
|
||||
MP_TYPE_IS(PerObject)
|
||||
MP_TYPE_IS(PerMaterial)
|
||||
|
@@ -15,6 +15,8 @@
|
||||
#include<hgl/graph/font/TextPrimitive.h>
|
||||
#include<hgl/type/ResManage.h>
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/VKDescriptorBindingManage.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
using MaterialID =int;
|
||||
using MaterialInstanceID =int;
|
||||
@@ -47,8 +49,7 @@ class RenderResource
|
||||
IDResManage<TextureID, Texture> rm_textures; ///<纹理合集
|
||||
IDResManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> global_buffer_map; ///<全局Buffer(UBO/SSBO)
|
||||
Map<AnsiString,Texture *> global_texture_map; ///<全局Texture
|
||||
DescriptorBinding global_binding; ///<全局属性描述符绑定管理
|
||||
|
||||
public:
|
||||
|
||||
@@ -68,13 +69,10 @@ public: //Add
|
||||
|
||||
public: //全局属性(对应shader中的PerGlobal set合集)
|
||||
|
||||
void SetGlobal(const AnsiString &name,DeviceBuffer *buf);
|
||||
void AddGlobalUBO(const AnsiString &name,DeviceBuffer *buf){global_binding.AddUBO(name,buf);}
|
||||
void AddGlobalSSBO(const AnsiString &name,DeviceBuffer *buf){global_binding.AddSSBO(name,buf);}
|
||||
|
||||
DeviceBuffer *GetGlobal(const AnsiString &name);
|
||||
|
||||
void Free(DeviceBuffer *);
|
||||
|
||||
void BindGlobalDescriptor(MaterialInstance *);
|
||||
bool BindGlobal(MaterialInstance *mi){return global_binding.Bind(mi->GetMP(DescriptorSetType::Global));}
|
||||
|
||||
public: // VBO/VAO
|
||||
|
||||
|
Reference in New Issue
Block a user