2020-09-02 18:16:15 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_DATABASE_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VULKAN_DATABASE_INCLUDE
|
|
|
|
|
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKMaterial.h>
|
|
|
|
|
#include<hgl/graph/VKPipeline.h>
|
2023-02-13 11:50:55 +08:00
|
|
|
|
#include<hgl/graph/VKDescriptorSet.h>
|
2022-06-24 17:51:05 +08:00
|
|
|
|
#include<hgl/graph/VKPrimitive.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKBuffer.h>
|
|
|
|
|
#include<hgl/graph/VKSampler.h>
|
|
|
|
|
#include<hgl/graph/VKTexture.h>
|
2021-06-16 11:43:19 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialParameters.h>
|
2021-06-16 20:29:25 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialInstance.h>
|
2022-06-24 21:06:38 +08:00
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
2022-06-24 17:51:05 +08:00
|
|
|
|
#include<hgl/graph/font/TextPrimitive.h>
|
2023-07-28 20:17:46 +08:00
|
|
|
|
#include<hgl/type/ObjectManage.h>
|
2023-03-17 21:06:05 +08:00
|
|
|
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
2023-03-25 23:12:08 +08:00
|
|
|
|
#include<hgl/graph/VKDescriptorBindingManage.h>
|
2023-10-13 10:47:42 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2023-03-25 23:12:08 +08:00
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-10-11 19:02:17 +08:00
|
|
|
|
|
|
|
|
|
namespace mtl
|
|
|
|
|
{
|
|
|
|
|
struct Material2DCreateConfig;
|
|
|
|
|
struct Material3DCreateConfig;
|
|
|
|
|
}//namespace mtl
|
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
using MaterialID =int;
|
|
|
|
|
using MaterialInstanceID =int;
|
|
|
|
|
using BufferID =int;
|
2023-02-13 11:48:53 +08:00
|
|
|
|
using DescriptorSetID =int;
|
2022-06-24 17:51:05 +08:00
|
|
|
|
using PrimitiveID =int;
|
2022-06-24 21:06:38 +08:00
|
|
|
|
using RenderableID =int;
|
2020-09-02 18:16:15 +08:00
|
|
|
|
using SamplerID =int;
|
|
|
|
|
using TextureID =int;
|
|
|
|
|
|
|
|
|
|
class VertexAttribData;
|
|
|
|
|
|
2023-06-12 16:30:16 +08:00
|
|
|
|
using ShaderModuleMapByName=ObjectMap<AnsiString,ShaderModule>;
|
|
|
|
|
constexpr const size_t VK_SHADER_STAGE_TYPE_COUNT=20;//GetBitOffset((uint32_t)VK_SHADER_STAGE_CLUSTER_CULLING_BIT_HUAWEI)+1;
|
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
/**
|
2020-09-02 18:18:57 +08:00
|
|
|
|
* 资源管理,用于管理场景内所需的所有数据
|
2020-09-02 18:16:15 +08:00
|
|
|
|
*/
|
2020-10-21 12:39:22 +08:00
|
|
|
|
class RenderResource
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUDevice *device;
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
2023-06-12 16:30:16 +08:00
|
|
|
|
ShaderModuleMapByName shader_module_by_name[VK_SHADER_STAGE_TYPE_COUNT];
|
2023-06-05 17:07:37 +08:00
|
|
|
|
Map<AnsiString,Material *> material_by_name;
|
2020-10-22 12:22:10 +08:00
|
|
|
|
Map<OSString,Texture *> texture_by_name;
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
2023-07-28 20:17:46 +08:00
|
|
|
|
IDObjectManage<MaterialID, Material> rm_material; ///<材质合集
|
|
|
|
|
IDObjectManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
|
|
|
|
|
IDObjectManage<DescriptorSetID, DescriptorSet> rm_desc_sets; ///<描述符合集
|
|
|
|
|
IDObjectManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
|
|
|
|
|
IDObjectManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
|
|
|
|
|
IDObjectManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
|
|
|
|
|
IDObjectManage<TextureID, Texture> rm_textures; ///<纹理合集
|
|
|
|
|
IDObjectManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2023-10-13 10:42:21 +08:00
|
|
|
|
private:
|
|
|
|
|
|
2023-10-13 10:47:42 +08:00
|
|
|
|
void AddBuffer(const AnsiString &buf_name,DeviceBuffer *buf)
|
|
|
|
|
{
|
|
|
|
|
rm_buffers.Add(buf);
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
DebugUtils *du=device->GetDebugUtils();
|
|
|
|
|
|
|
|
|
|
if(du)
|
|
|
|
|
{
|
|
|
|
|
du->SetBuffer(buf->GetBuffer(),buf_name+":Buffer");
|
|
|
|
|
du->SetDeviceMemory(buf->GetVkMemory(),buf_name+":Memory");
|
|
|
|
|
}
|
|
|
|
|
#endif//_DEBUG
|
|
|
|
|
}
|
2023-10-13 10:42:21 +08:00
|
|
|
|
|
2023-03-27 10:22:55 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2024-04-03 00:14:09 +08:00
|
|
|
|
GPUDevice *GetDevice(){return device;}
|
|
|
|
|
|
2023-03-27 10:22:55 +08:00
|
|
|
|
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
|
2024-03-09 23:35:56 +08:00
|
|
|
|
DescriptorBinding static_descriptor; ///<静态属性描述符绑定管理
|
|
|
|
|
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
|
2023-03-21 21:37:03 +08:00
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2024-03-09 23:35:56 +08:00
|
|
|
|
RenderResource(GPUDevice *dev):device(dev),
|
|
|
|
|
static_descriptor(DescriptorSetType::Static),
|
|
|
|
|
global_descriptor(DescriptorSetType::Global)
|
|
|
|
|
{}
|
2020-10-21 12:39:22 +08:00
|
|
|
|
virtual ~RenderResource()=default;
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2024-05-25 01:48:15 +08:00
|
|
|
|
public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
|
|
|
|
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
|
2021-06-16 20:29:25 +08:00
|
|
|
|
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
|
2023-02-13 11:48:53 +08:00
|
|
|
|
DescriptorSetID Add(DescriptorSet * ds ){return rm_desc_sets.Add(ds);}
|
2022-06-24 17:51:05 +08:00
|
|
|
|
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
|
2023-02-13 11:48:53 +08:00
|
|
|
|
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
|
|
|
|
|
TextureID Add(Texture * t ){return rm_textures.Add(t);}
|
2022-06-24 21:06:38 +08:00
|
|
|
|
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2024-04-24 01:44:01 +08:00
|
|
|
|
public: // VAB/VAO
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2024-04-24 01:38:55 +08:00
|
|
|
|
VAB *CreateVAB(VkFormat format,uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
|
|
|
|
VAB *CreateVAB(VkFormat format,uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVAB(format, count, nullptr, sm);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2023-10-13 10:42:21 +08:00
|
|
|
|
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
|
|
|
|
DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,SharingMode sm=SharingMode::Exclusive){return Create##name(buf_name,size,nullptr,sm);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
|
|
|
|
SCENE_DB_CREATE_FUNC(UBO)
|
|
|
|
|
SCENE_DB_CREATE_FUNC(SSBO)
|
|
|
|
|
SCENE_DB_CREATE_FUNC(INBO)
|
|
|
|
|
|
|
|
|
|
#undef SCENE_DB_CREATE_FUNC
|
|
|
|
|
|
2020-10-14 21:05:12 +08:00
|
|
|
|
IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
2024-03-06 22:51:07 +08:00
|
|
|
|
IndexBuffer *CreateIBO8 ( uint32_t count,const uint8 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8 ,count,(void *)data,sm);}
|
2020-10-14 21:05:12 +08:00
|
|
|
|
IndexBuffer *CreateIBO16( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,(void *)data,sm);}
|
|
|
|
|
IndexBuffer *CreateIBO32( uint32_t count,const uint32 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,(void *)data,sm);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2024-03-06 22:51:07 +08:00
|
|
|
|
IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(index_type, count,nullptr,sm);}
|
|
|
|
|
IndexBuffer *CreateIBO8 ( uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,nullptr,sm);}
|
|
|
|
|
IndexBuffer *CreateIBO16( uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,nullptr,sm);}
|
|
|
|
|
IndexBuffer *CreateIBO32( uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32, count,nullptr,sm);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2020-09-19 23:49:32 +08:00
|
|
|
|
public: //Material
|
|
|
|
|
|
2023-06-12 16:30:16 +08:00
|
|
|
|
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
2023-05-16 02:23:45 +08:00
|
|
|
|
Material * CreateMaterial(const mtl::MaterialCreateInfo *);
|
2023-10-11 19:02:17 +08:00
|
|
|
|
Material * LoadMaterial(const AnsiString &,mtl::Material2DCreateConfig *);
|
|
|
|
|
Material * LoadMaterial(const AnsiString &,mtl::Material3DCreateConfig *);
|
2023-03-17 21:06:05 +08:00
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
2023-10-11 19:14:24 +08:00
|
|
|
|
|
|
|
|
|
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg,const void *,const int);
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
MaterialInstance * CreateMaterialInstance(Material *mtl,const VILConfig *vil_cfg,const T *data)
|
|
|
|
|
{
|
2023-10-13 19:22:11 +08:00
|
|
|
|
return CreateMaterialInstance(mtl,vil_cfg,data,sizeof(T));
|
2023-10-11 19:14:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 02:23:45 +08:00
|
|
|
|
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
|
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
|
|
|
|
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
2021-11-22 14:06:04 +08:00
|
|
|
|
Sampler * CreateSampler(Texture *);
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2020-10-22 12:22:10 +08:00
|
|
|
|
public: //texture
|
|
|
|
|
|
2020-10-24 21:50:36 +08:00
|
|
|
|
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
|
2022-01-07 16:55:39 +08:00
|
|
|
|
TextureCube * LoadTextureCube(const OSString &,bool auto_mipmaps=false);
|
2020-10-22 12:22:10 +08:00
|
|
|
|
|
2023-10-12 05:55:39 +08:00
|
|
|
|
Texture2DArray * CreateTexture2DArray(const AnsiString &name,const uint32_t width,const uint32_t height,const uint32_t layer,const VkFormat &fmt,bool auto_mipmaps=false);
|
2023-09-25 20:32:12 +08:00
|
|
|
|
bool LoadTexture2DToArray(Texture2DArray *,const uint32_t layer,const OSString &);
|
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
public: //Get
|
|
|
|
|
|
|
|
|
|
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
2021-06-16 20:29:25 +08:00
|
|
|
|
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
|
2023-02-13 11:48:53 +08:00
|
|
|
|
DescriptorSet * GetDescSets (const DescriptorSetID &id){return rm_desc_sets.Get(id);}
|
2022-06-24 21:06:38 +08:00
|
|
|
|
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
|
2023-02-13 11:48:53 +08:00
|
|
|
|
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
|
|
|
|
|
Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);}
|
2023-05-22 21:28:48 +08:00
|
|
|
|
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
2020-10-21 12:39:22 +08:00
|
|
|
|
};//class RenderResource
|
2020-09-02 18:16:15 +08:00
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_DATABASE_INCLUDE
|