added VKUBODynamic.h and support from VKArrayBuffer.h
This commit is contained in:
parent
cb09767151
commit
05e96c58ba
@ -1 +1 @@
|
|||||||
Subproject commit eaa42e6c967b605c78e959cd5db6d10e3f443205
|
Subproject commit fd78d7e14b95e01e37eb5e631cbd6967e284fb95
|
@ -30,7 +30,7 @@ constexpr float color_data[VERTEX_COUNT][4]=
|
|||||||
{0,0,1,1}
|
{0,0,1,1}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||||
|
|
||||||
class TestApp:public VulkanApplicationFramework
|
class TestApp:public VulkanApplicationFramework
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,12 @@ namespace hgl
|
|||||||
virtual bool ExpendNode(SceneNode *);
|
virtual bool ExpendNode(SceneNode *);
|
||||||
virtual void End();
|
virtual void End();
|
||||||
|
|
||||||
|
bool BindPerFrameDescriptor();
|
||||||
|
bool BindPerMaterialDescriptor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Material * last_mtl;
|
||||||
Pipeline * last_pipeline;
|
Pipeline * last_pipeline;
|
||||||
MaterialParameters *last_mp[DESCRIPTOR_SET_TYPE_COUNT];
|
MaterialParameters *last_mp[DESCRIPTOR_SET_TYPE_COUNT];
|
||||||
uint32_t last_vbo;
|
uint32_t last_vbo;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
|
#include<hgl/graph/VKUBODynamic.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
class Collection;
|
class Collection;
|
||||||
@ -29,6 +30,11 @@ namespace hgl
|
|||||||
|
|
||||||
Collection *coll;
|
Collection *coll;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void * Map(const uint32 start,const uint32 count);
|
||||||
|
void Flush(const uint32 count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il,VkDescriptorType dt);
|
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il,VkDescriptorType dt);
|
||||||
@ -41,8 +47,27 @@ namespace hgl
|
|||||||
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
uint32 Alloc(const uint32 max_count); ///<预分配空间
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
void * Map(const uint32 start,const uint32 count);
|
template<typename T>
|
||||||
void Flush(const uint32 count);
|
bool Start(UBODynamicAccess<T> *ubo_access,const uint32 start,const uint32 count)
|
||||||
|
{
|
||||||
|
if(!ubo_access)return(false);
|
||||||
|
|
||||||
|
void *ptr=Map(start,count);
|
||||||
|
|
||||||
|
if(!ptr)return(false);
|
||||||
|
|
||||||
|
ubo_access->Start((uchar *)ptr,offset_alignment,count);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void End(UBODynamicAccess<void> *ubo_access)
|
||||||
|
{
|
||||||
|
if(!ubo_access)return;
|
||||||
|
|
||||||
|
Flush(ubo_access->GetCount());
|
||||||
|
|
||||||
|
ubo_access->Restart();
|
||||||
|
}
|
||||||
};//class GPUArrayBuffer
|
};//class GPUArrayBuffer
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -33,11 +33,6 @@ public:
|
|||||||
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
|
const uint32_t GetDescriptorCount ()const{return desc_manager->GetBindCount(set_type);} ///<获取总共需要绑定的描述符数量
|
||||||
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
|
const BindingMapArray & GetBindingMap ()const{return desc_manager->GetBindingMap(set_type);}
|
||||||
|
|
||||||
const uint32_t GetDynamicCount ()const //返回动态ubo/ssbo总量
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
|
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
|
||||||
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了
|
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了
|
||||||
|
|
||||||
|
80
inc/hgl/graph/VKUBODynamic.h
Normal file
80
inc/hgl/graph/VKUBODynamic.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#ifndef HGL_GRAPH_UBO_DYNAMIC_INCLUDE
|
||||||
|
#define HGL_GRAPH_UBO_DYNAMIC_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/graph/VKArrayBuffer.h>
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
template<typename T> class UBODynamicAccess
|
||||||
|
{
|
||||||
|
uchar *pointer;
|
||||||
|
uchar *current;
|
||||||
|
|
||||||
|
uint unit_size;
|
||||||
|
|
||||||
|
uint count;
|
||||||
|
uint index;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UBODynamicAccess()
|
||||||
|
{
|
||||||
|
Restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Restart()
|
||||||
|
{
|
||||||
|
pointer=nullptr;
|
||||||
|
current=nullptr;
|
||||||
|
unit_size=0;
|
||||||
|
count=0;
|
||||||
|
index=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start(uchar *buf,const uint us,const uint c)
|
||||||
|
{
|
||||||
|
current=pointer=buf;
|
||||||
|
unit_size=us;
|
||||||
|
count=c;
|
||||||
|
index=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend class GPUArrayBuffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const uint GetCount()const{return count;}
|
||||||
|
const uint GetCurrentIndex()const{return index;}
|
||||||
|
const uint GetOffsetBytes()const{return index*unit_size;}
|
||||||
|
|
||||||
|
bool Write(uchar *src)
|
||||||
|
{
|
||||||
|
if(!src)return(false);
|
||||||
|
if(index>=count)return(false);
|
||||||
|
|
||||||
|
memcpy(current,src,sizeof(T));
|
||||||
|
current+=unit_size;
|
||||||
|
++index;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Write(uchar *src,const uint c)
|
||||||
|
{
|
||||||
|
if(!src)return(false);
|
||||||
|
if(c<=0)return(false);
|
||||||
|
if(index+c>count)return(false);
|
||||||
|
|
||||||
|
for(uint i=0;i<c;i++)
|
||||||
|
{
|
||||||
|
memcpy(current,src,sizeof(T));
|
||||||
|
current+=unit_size;
|
||||||
|
src+=sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
index+=c;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
};//template<typename T> class UBODynamicAccess
|
||||||
|
VK_NAMESPACE_END
|
||||||
|
#endif//HGL_GRAPH_UBO_DYNAMIC_INCLUDE
|
@ -185,6 +185,7 @@ SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h
|
|||||||
${SG_INCLUDE_PATH}/VKMaterialParameters.h
|
${SG_INCLUDE_PATH}/VKMaterialParameters.h
|
||||||
${SG_INCLUDE_PATH}/VKMaterialInstance.h
|
${SG_INCLUDE_PATH}/VKMaterialInstance.h
|
||||||
${SG_INCLUDE_PATH}/VKDescriptorBindingManage.h
|
${SG_INCLUDE_PATH}/VKDescriptorBindingManage.h
|
||||||
|
${SG_INCLUDE_PATH}/VKUBODynamic.h
|
||||||
Vulkan/VKDescriptorBindingManage.cpp
|
Vulkan/VKDescriptorBindingManage.cpp
|
||||||
Vulkan/VKMaterial.cpp
|
Vulkan/VKMaterial.cpp
|
||||||
Vulkan/VKMaterialParameters.cpp
|
Vulkan/VKMaterialParameters.cpp
|
||||||
|
@ -11,9 +11,10 @@
|
|||||||
/**
|
/**
|
||||||
* 理论上讲,我们需要按以下顺序排序
|
* 理论上讲,我们需要按以下顺序排序
|
||||||
*
|
*
|
||||||
* for(pipeline)
|
* for(material)
|
||||||
* for(material_instance)
|
* for(pipeline)
|
||||||
* for(vbo)
|
* for(material_instance)
|
||||||
|
* for(vbo)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
@ -24,6 +25,15 @@ int Comparator<RenderNode2DPointer>::compare(const RenderNode2DPointer &obj_one,
|
|||||||
hgl::graph::Renderable *ri_one=obj_one->ri;
|
hgl::graph::Renderable *ri_one=obj_one->ri;
|
||||||
hgl::graph::Renderable *ri_two=obj_two->ri;
|
hgl::graph::Renderable *ri_two=obj_two->ri;
|
||||||
|
|
||||||
|
//比较材质
|
||||||
|
{
|
||||||
|
off=ri_one->GetMaterial()
|
||||||
|
-ri_two->GetMaterial();
|
||||||
|
|
||||||
|
if(off)
|
||||||
|
return off;
|
||||||
|
}
|
||||||
|
|
||||||
//比较管线
|
//比较管线
|
||||||
{
|
{
|
||||||
off=ri_one->GetPipeline()
|
off=ri_one->GetPipeline()
|
||||||
@ -34,18 +44,18 @@ int Comparator<RenderNode2DPointer>::compare(const RenderNode2DPointer &obj_one,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//比较材质实例
|
//比较材质实例
|
||||||
{
|
//{
|
||||||
for(int i =(int)hgl::graph::DescriptorSetType::BEGIN_RANGE;
|
// for(int i =(int)hgl::graph::DescriptorSetType::BEGIN_RANGE;
|
||||||
i<=(int)hgl::graph::DescriptorSetType::END_RANGE;
|
// i<=(int)hgl::graph::DescriptorSetType::END_RANGE;
|
||||||
i++)
|
// i++)
|
||||||
{
|
// {
|
||||||
off=ri_one->GetMP((hgl::graph::DescriptorSetType)i)
|
// off=ri_one->GetMP((hgl::graph::DescriptorSetType)i)
|
||||||
-ri_two->GetMP((hgl::graph::DescriptorSetType)i);
|
// -ri_two->GetMP((hgl::graph::DescriptorSetType)i);
|
||||||
|
|
||||||
if(off)
|
// if(off)
|
||||||
return off;
|
// return off;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
//比较vbo+ebo
|
//比较vbo+ebo
|
||||||
{
|
{
|
||||||
@ -71,6 +81,7 @@ namespace hgl
|
|||||||
ubo_offset =0;
|
ubo_offset =0;
|
||||||
ubo_align =0;
|
ubo_align =0;
|
||||||
|
|
||||||
|
last_mtl =nullptr;
|
||||||
last_pipeline =nullptr;
|
last_pipeline =nullptr;
|
||||||
hgl_zero(last_mp);
|
hgl_zero(last_mp);
|
||||||
last_vbo =0;
|
last_vbo =0;
|
||||||
@ -180,6 +191,41 @@ namespace hgl
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderList2D::BindPerFrameDescriptor()
|
||||||
|
{
|
||||||
|
if(!cmd_buf)return(false);
|
||||||
|
|
||||||
|
for(Material *mtl:material_sets)
|
||||||
|
{
|
||||||
|
MaterialParameters *mp=mtl->GetMP(DescriptorSetType::PerFrame);
|
||||||
|
|
||||||
|
if(!mp)continue;
|
||||||
|
|
||||||
|
//if(mp->BindUBO("r_scene_info",mvp_array->GetBuffer(),true))
|
||||||
|
// mp->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderList2D::BindPerMaterialDescriptor()
|
||||||
|
{
|
||||||
|
//为每个材质实例,绑定它们的描述符
|
||||||
|
if(!cmd_buf)return(false);
|
||||||
|
|
||||||
|
for(Material *mtl:material_sets)
|
||||||
|
{
|
||||||
|
MaterialParameters *mp=mtl->GetMP(DescriptorSetType::PerMaterial);
|
||||||
|
|
||||||
|
if(!mp)continue;
|
||||||
|
|
||||||
|
//if(mp->BindUBO("r_scene_info",mvp_array->GetBuffer(),true))
|
||||||
|
// mp->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
void RenderList2D::Render(Renderable *ri)
|
void RenderList2D::Render(Renderable *ri)
|
||||||
{
|
{
|
||||||
if(last_pipeline!=ri->GetPipeline())
|
if(last_pipeline!=ri->GetPipeline())
|
||||||
@ -265,11 +311,14 @@ namespace hgl
|
|||||||
|
|
||||||
cmd_buf=cb;
|
cmd_buf=cb;
|
||||||
|
|
||||||
last_pipeline=nullptr;
|
last_mtl=nullptr;
|
||||||
|
last_pipeline=nullptr;
|
||||||
hgl_zero(last_mp);
|
hgl_zero(last_mp);
|
||||||
last_vbo=0;
|
last_vbo=0;
|
||||||
ubo_offset=0;
|
ubo_offset=0;
|
||||||
|
|
||||||
|
BindPerFrameDescriptor();
|
||||||
|
|
||||||
for(Renderable *ri:ri_list)
|
for(Renderable *ri:ri_list)
|
||||||
Render(ri);
|
Render(ri);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user