added VKUBODynamic.h and support from VKArrayBuffer.h

This commit is contained in:
2023-03-28 21:52:08 +08:00
parent cb09767151
commit 05e96c58ba
8 changed files with 178 additions and 24 deletions

View File

@@ -46,8 +46,12 @@ namespace hgl
virtual bool ExpendNode(SceneNode *);
virtual void End();
bool BindPerFrameDescriptor();
bool BindPerMaterialDescriptor();
private:
Material * last_mtl;
Pipeline * last_pipeline;
MaterialParameters *last_mp[DESCRIPTOR_SET_TYPE_COUNT];
uint32_t last_vbo;

View File

@@ -2,6 +2,7 @@
#define HGL_GRAPH_VULKAN_ARRAY_BUFFER_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/VKUBODynamic.h>
namespace hgl
{
class Collection;
@@ -29,6 +30,11 @@ namespace hgl
Collection *coll;
protected:
void * Map(const uint32 start,const uint32 count);
void Flush(const uint32 count);
public:
GPUArrayBuffer(GPUDevice *dev,VkBufferUsageFlags flags,const uint il,VkDescriptorType dt);
@@ -41,8 +47,27 @@ namespace hgl
uint32 Alloc(const uint32 max_count); ///<预分配空间
void Clear();
void * Map(const uint32 start,const uint32 count);
void Flush(const uint32 count);
template<typename T>
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
}//namespace graph
}//namespace hgl

View File

@@ -33,11 +33,6 @@ public:
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总量
{
}
const uint32_t GetBoundCount ()const{return descriptor_set->GetCount();} ///<获取已经绑好的数量
const bool IsReady ()const{return descriptor_set->IsReady();} ///<是否全部绑好了

View 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