This commit is contained in:
hyzboy 2023-03-26 00:04:50 +08:00
commit 88f23d9a07
No known key found for this signature in database
GPG Key ID: 067EE4525D4FB6D3
22 changed files with 306 additions and 349 deletions

View File

@ -1,5 +1,5 @@
# ULRE
experiment project - Ultra Light Rendering Engine
experiment project - Ultra Lightweight Rendering Engine
ULRE is a project of experimental nature,Used to experiment with various rendering related techniques,And do some examples.

View File

@ -60,7 +60,7 @@ private:
if(!material_instance)
return(false);
db->BindGlobalDescriptor(material_instance);
db->BindGlobal(material_instance);
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target

View File

@ -6,6 +6,7 @@
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/2d/VertexColor2D.h>
#include<hgl/graph/RenderList2D.h>
using namespace hgl;
using namespace hgl::graph;
@ -33,7 +34,7 @@ class TestApp:public VulkanApplicationFramework
private:
SceneNode render_root;
RenderList * render_list =nullptr;
RenderList2D * render_list =nullptr;
MaterialInstance * material_instance =nullptr;
Renderable * render_obj =nullptr;
@ -73,7 +74,7 @@ private:
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
render_list->Expend(&render_root);
return(true);
}
@ -90,7 +91,7 @@ public:
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
render_list=new RenderList2D(device);
if(!InitMaterial())
return(false);

View File

@ -19,7 +19,7 @@
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKRenderTarget.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/RenderList2D.h>
#include<hgl/graph/mtl/StdMaterial.h>
#include<hgl/color/Color.h>
#include<hgl/Time.h>
@ -142,7 +142,7 @@ public:
ubo_vp_info=db->CreateUBO(sizeof(ViewportInfo),&vp_info);
db->SetGlobal(GlobalDescriptor::ViewportInfo.name,ubo_vp_info);
db->AddGlobalUBO(GlobalDescriptor::ViewportInfo.name,ubo_vp_info);
}
return(true);
@ -248,7 +248,7 @@ public:
return BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),ri);
}
void BuildCommandBuffer(uint32_t index,RenderList *rl)
void BuildCommandBuffer(uint32_t index,RenderList2D *rl)
{
if(!rl)return;
@ -263,13 +263,13 @@ public:
cb->End();
}
void BuildCommandBuffer(RenderList *rl)
void BuildCommandBuffer(RenderList2D *rl)
{
for(int32_t i=0;i<swap_chain_count;i++)
BuildCommandBuffer(i,rl);
}
void BuildCurrentCommandBuffer(RenderList *rl)
void BuildCurrentCommandBuffer(RenderList2D *rl)
{
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),rl);
}

View File

@ -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

View File

@ -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

View File

@ -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;
};

View File

@ -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

View 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

View File

@ -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);} \

View File

@ -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

View File

@ -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);}

View File

@ -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)

View File

@ -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

View File

@ -41,9 +41,10 @@ SET(SCENE_GRAPH_HEADER ${SG_INCLUDE_PATH}/SceneInfo.h
${SG_INCLUDE_PATH}/RenderList2D.h
)
SET(SCENE_GRAPH_SOURCE RenderList.cpp
SET(SCENE_GRAPH_SOURCE
#RenderList.cpp
RenderList2D.cpp
RenderList3D.cpp
#RenderList3D.cpp
SceneNode.cpp
SceneOrient.cpp)
@ -118,6 +119,7 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
Vulkan/VKMemory.cpp
Vulkan/VKMemoryAllocator.cpp
Vulkan/VKBuffer.cpp
Vulkan/VKArrayBuffer.cpp
)
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
@ -182,6 +184,8 @@ SET(VK_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/VKImageView.h
SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h
${SG_INCLUDE_PATH}/VKMaterialParameters.h
${SG_INCLUDE_PATH}/VKMaterialInstance.h
${SG_INCLUDE_PATH}/VKDescriptorBindingManage.h
Vulkan/VKDescriptorBindingManage.cpp
Vulkan/VKMaterial.cpp
Vulkan/VKMaterialParameters.cpp
Vulkan/VKMaterialInstance.cpp)

View File

@ -1,5 +1,4 @@
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/RenderList2D.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKPrimitive.h>
@ -15,11 +14,10 @@
* for(pipeline)
* for(material_instance)
* for(vbo)
* for(distance)
*/
template<>
int Comparator<RenderNode3DPointer>::compare(const RenderNode3DPointer &obj_one,const RenderNode3DPointer &obj_two) const
int Comparator<RenderNode2DPointer>::compare(const RenderNode2DPointer &obj_one,const RenderNode2DPointer &obj_two) const
{
int off;
@ -58,17 +56,6 @@ int Comparator<RenderNode3DPointer>::compare(const RenderNode3DPointer &obj_one,
return off;
}
//比较距离
{
const double dist=obj_one->distance_to_camera_square-
obj_two->distance_to_camera_square;
//由于距离差距可能会小于1但又返回int所以需要做如此处理
if(dist>0)return 1;else
if(dist<0)return -1;
}
return 0;
}
@ -76,7 +63,7 @@ namespace hgl
{
namespace graph
{
RenderList::RenderList(GPUDevice *dev)
RenderList2D::RenderList2D(GPUDevice *dev)
{
device =dev;
cmd_buf =nullptr;
@ -87,13 +74,15 @@ namespace hgl
last_pipeline =nullptr;
hgl_zero(last_mp);
last_vbo =0;
// mvp_array =new GPUArrayBuffer(device,VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,MVPMatrixBytes);
}
RenderList::~RenderList()
RenderList2D::~RenderList2D()
{
}
bool RenderList::Begin()
bool RenderList2D::Begin()
{
render_node_list.ClearData();
ri_list.ClearData();
@ -103,7 +92,7 @@ namespace hgl
return(true);
}
void RenderList::End()
void RenderList2D::End()
{
if(render_node_list.GetCount()<=0)return;
@ -116,46 +105,46 @@ namespace hgl
{
//按当前总节点数量分配UBO
mvp_array->Alloc(count);
mvp_array->Clear();
// mvp_array->Alloc(count);
// mvp_array->Clear();
ri_list.ClearData();
ri_list.SetCount(count);
ri_list.SetCount(count);
}
{
ubo_align=mvp_array->GetUnitSize();
// ubo_align=mvp_array->GetUnitSize();
char *mp=(char *)(mvp_array->Map(0,count));
// char *mp=(char *)(mvp_array->Map(0,count));
Renderable **ri=ri_list.GetData();
for(RenderNode *node:render_node_list) //未来可能要在Expend处考虑做去重
for(RenderNode2D *node:render_node_list) //未来可能要在Expend处考虑做去重
{
memcpy(mp,&(node->matrix),MVPMatrixBytes);
mp+=ubo_align;
// memcpy(mp,&(node->matrix),MVPMatrixBytes);
// mp+=ubo_align;
(*ri)=node->ri;
++ri;
}
mvp_array->Flush(count);
// mvp_array->Flush(count);
}
}
//为所有的材质绑定
for(Material *mtl:material_sets)
{
MaterialParameters *mp=mtl->GetMP(DescriptorSetType::PerObject);
//for(Material *mtl:material_sets)
//{
// MaterialParameters *mp=mtl->GetMP(DescriptorSetType::PerObject);
if(mp)
{
if(mp->BindUBO("r_scene_info",mvp_array->GetBuffer(),true))
mp->Update();
}
}
// if(mp)
// {
// if(mp->BindUBO("r_scene_info",mvp_array->GetBuffer(),true))
// mp->Update();
// }
//}
}
bool RenderList::Expend(SceneNode *sn)
bool RenderList2D::ExpendNode(SceneNode *sn)
{
if(!sn)return(false);
@ -163,14 +152,9 @@ namespace hgl
if(ri)
{
RenderNode *rn=new RenderNode;
RenderNode2D *rn=new RenderNode2D;
rn->matrix.Set(sn->GetLocalToWorldMatrix(),camera_info.vp,camera_info.view);
rn->WorldCenter=sn->GetWorldCenter();
rn->distance_to_camera_square=length_squared(rn->WorldCenter,camera_info.pos);
// rn->distance_to_camera=sqrtf(rn->distance_to_camera_square);
rn->local_to_world=sn->GetLocalToWorldMatrix();
rn->ri=ri;
@ -185,20 +169,18 @@ namespace hgl
return(true);
}
bool RenderList::Expend(const CameraInfo &ci,SceneNode *sn)
bool RenderList2D::Expend(SceneNode *sn)
{
if(!device|!sn)return(false);
camera_info=ci;
Begin();
Expend(sn);
ExpendNode(sn);
End();
return(true);
}
void RenderList::Render(Renderable *ri)
void RenderList2D::Render(Renderable *ri)
{
if(last_pipeline!=ri->GetPipeline())
{
@ -273,7 +255,7 @@ namespace hgl
}
}
bool RenderList::Render(RenderCmdBuffer *cb)
bool RenderList2D::Render(RenderCmdBuffer *cb)
{
if(!cb)
return(false);

View File

@ -1,5 +1,6 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKBuffer.h>
VK_NAMESPACE_BEGIN
bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const

View File

@ -1,6 +1,7 @@
#include<hgl/graph/VKDevice.h>
#include<hgl/graph/VKImageCreateInfo.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VKBuffer.h>
#include"BufferImageCopy2D.h"
VK_NAMESPACE_BEGIN
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);

View File

@ -1,60 +1,73 @@
#include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/VKMemoryAllocator.h>
#include<hgl/type/Collection.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKDevice.h>
namespace hgl
{
namespace graph
{
/**
*
* @param d
* @param s
* @param c
*/
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *d,const uint32_t s,const uint32_t c)
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il,VkDescriptorType dt)
{
device=d;
device=dev;
buffer_usage_flags=flags;
item_length=il;
item_size=s;
count=c;
alloc_count=power_to_2(c);
if(dt==VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
||dt==VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)
offset_alignment=device->GetUBOAlign();
else
if(dt==VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
||dt==VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)
offset_alignment=device->GetSSBOAlign();
else
offset_alignment=0;
buf_gpu=nullptr;
buf_cpu=nullptr;
offset=nullptr;
const uint32_t unit_size=hgl_align<uint32_t>(item_length,offset_alignment);
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);
}
GPUArrayBuffer::~GPUArrayBuffer()
{
SAFE_CLEAR_ARRAY(offset);
SAFE_CLEAR(buf_gpu);
delete coll;
}
const uint32_t GPUArrayBuffer::GetUnitSize()const
{
return coll->GetUnitBytes();
}
DeviceBuffer *GPUArrayBuffer::GetBuffer()
{
return vk_ma->GetBuffer();
}
uint32 GPUArrayBuffer::Alloc(const uint32 max_count) ///<预分配空间
{
if(!coll->Alloc(max_count))
return(0);
return coll->GetAllocCount();
}
void GPUArrayBuffer::Clear()
{
count=0;
coll->Clear();
}
bool GPUArrayBuffer::Init(const uint32_t c)
void *GPUArrayBuffer::Map(const uint32 start,const uint32 count)
{
if(c<=0)return(false);
return coll->Map(start,count);
}
if(!buf_gpu)
{
count=c;
alloc_count=power_to_2(count);
total_bytes=item_size*alloc_count;
if(total_bytes<=0)return(false);
buf_gpu=device->CreateUBO(total_bytes);
buf_cpu=(uint8 *)(buf_gpu->Map());
offset=new uint32_t[alloc_count];
}
else
{
}
void GPUArrayBuffer::Flush(const uint32 count)
{
vk_ma->Flush(count*GetUnitSize());
}
}//namespace graph
}//namespace hgl

View File

@ -0,0 +1,44 @@
#include<hgl/graph/VKDescriptorBindingManage.h>
#include<hgl/graph/VKMaterialParameters.h>
VK_NAMESPACE_BEGIN
bool DescriptorBinding::Bind(MaterialParameters *mp)
{
if(!mp)return(false);
{
const auto *dp=ubo_map.GetDataList();
for(uint i=0;i<ubo_map.GetCount();i++)
{
mp->BindUBO((*dp)->left,(*dp)->right);
++dp;
}
}
{
const auto *dp=ssbo_map.GetDataList();
for(uint i=0;i<ssbo_map.GetCount();i++)
{
mp->BindSSBO((*dp)->left,(*dp)->right);
++dp;
}
}
//{
// const auto *dp=texture_map.GetDataList();
// for(uint i=0;i<texture_map.GetCount();i++)
// {
// mp->BindImageSampler((*dp)->left,(*dp)->right);
// ++dp;
// }
//}
mp->Update();
}
VK_NAMESPACE_END

View File

@ -9,6 +9,11 @@ const VkDeviceSize GPUDevice::GetUBOAlign()
return attr->physical_device->GetUBOAlign();
}
const VkDeviceSize GPUDevice::GetSSBOAlign()
{
return attr->physical_device->GetSSBOAlign();
}
bool GPUDevice::CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage,VkDeviceSize range,VkDeviceSize size,const void *data,SharingMode sharing_mode)
{
BufferCreateInfo buf_info;

View File

@ -5,61 +5,6 @@
#include<hgl/graph/VKVertexAttribBuffer.h>
VK_NAMESPACE_BEGIN
void RenderResource::SetGlobal(const AnsiString &name,DeviceBuffer *buf)
{
if(!buf)return;
if(name.IsEmpty())return;
global_buffer_map.Add(name,buf);
}
DeviceBuffer *RenderResource::GetGlobal(const AnsiString &name)
{
if(name.IsEmpty())return(nullptr);
DeviceBuffer *buf;
if(global_buffer_map.Get(name,buf))
return buf;
else
return nullptr;
}
void RenderResource::Free(DeviceBuffer *buf)
{
rm_buffers.Release(buf);
global_buffer_map.DeleteByValue(buf);
}
void RenderResource::BindGlobalDescriptor(MaterialInstance *mi)
{
if(!mi)return;
const uint count=global_buffer_map.GetCount();
if(count<=0)return;
auto **gb_list=global_buffer_map.GetDataList();
auto *mp=mi->GetMP(DescriptorSetType::Global);
if(!mp)
return;
if(mp->GetDescriptorCount()<=0)
return;
for(uint i=0;i<count;i++)
{
mp->BindUBO((*gb_list)->left,(*gb_list)->right);
++gb_list;
}
mp->Update();
}
VBO *RenderResource::CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
{
VBO *vb=device->CreateVBO(format,count,data,sharing_mode);