diff --git a/CMCore b/CMCore index 43bc9af0..6d9bced9 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 43bc9af0200846ce3f31fe97d963009e6b199f38 +Subproject commit 6d9bced95c7fb7fe7a3b6c734d0e7330bacfb2d6 diff --git a/inc/hgl/graph/RenderBufferName.h b/inc/hgl/graph/RenderBufferName.h index 353e453d..994c9747 100644 --- a/inc/hgl/graph/RenderBufferName.h +++ b/inc/hgl/graph/RenderBufferName.h @@ -9,7 +9,7 @@ const RENDER_BUFFER_NAME RenderBuffer_Swapchain ="Swapchain"; const RENDER_BUFFER_NAME RenderBuffer_Depth ="Depth"; const RENDER_BUFFER_NAME RenderBuffer_Stencil ="Stencil"; -const RENDER_BUFFER_NAME VBuffer_MeshID ="VB_MeshID"; ///< 所绘制的Mesh编号, R32UI格式 +const RENDER_BUFFER_NAME VBuffer_MeshID ="VB_MeshID"; ///< 所绘制的Mesh编号, RGBA8UI格式 const RENDER_BUFFER_NAME VBuffer_TriangleID ="VB_TriangleID"; ///< 三角形编号, R8UI格式 const RENDER_BUFFER_NAME VBuffer_MaterialID ="VB_MaterialID"; ///< 材质ID与材质实例ID, RG8UI格式 diff --git a/inc/hgl/graph/RenderFramework.h b/inc/hgl/graph/RenderFramework.h index 373a3981..bf377175 100644 --- a/inc/hgl/graph/RenderFramework.h +++ b/inc/hgl/graph/RenderFramework.h @@ -7,36 +7,41 @@ VK_NAMESPACE_BEGIN class GraphModule; +class TileData; +class TileFont; +class FontSource; -/** - * 渲染模块工作配置 - */ -class GraphModuleWorkConfig -{ - /** - * 渲染模块名称 - * 在render_module为nullptr时,用于创建或加载RenderModule。 - * 它和RenderModule返回的名称有可能一样,但也有可能不一样。 - */ - AnsiString render_module_name; - GraphModule *render_module=nullptr; - - BlendMode blend_mode; - RenderOrder render_order; - -public: - - const AnsiString &GetModuleName()const{return render_module_name;} ///<取得渲染模块名称 - - GraphModule *GetModule(){return render_module;} ///<取得渲染模块 - -public: - - GraphModuleWorkConfig(); - virtual ~GraphModuleWorkConfig()=default; -};//class GraphModuleWorkConfig +// +///** +// * 渲染模块工作配置 +// */ +//class GraphModuleWorkConfig +//{ +// /** +// * 渲染模块名称 +// * 在render_module为nullptr时,用于创建或加载RenderModule。 +// * 它和RenderModule返回的名称有可能一样,但也有可能不一样。 +// */ +// AnsiString render_module_name; +// GraphModule *render_module=nullptr; +// +// BlendMode blend_mode; +// RenderOrder render_order; +// +//public: +// +// const AnsiString &GetModuleName()const{return render_module_name;} ///<取得渲染模块名称 +// +// GraphModule *GetModule(){return render_module;} ///<取得渲染模块 +// +//public: +// +// GraphModuleWorkConfig(); +// virtual ~GraphModuleWorkConfig()=default; +//};//class GraphModuleWorkConfig class Window; +class VulkanInstance; class TextureManager; @@ -105,6 +110,12 @@ public: virtual void EndFrame(){}; ///<当前帧结束 virtual void MainLoop(); ///<主循环 + +public: //TileData + + TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集 + + TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体 };//class RenderFramework VK_NAMESPACE_END diff --git a/inc/hgl/graph/TileData.h b/inc/hgl/graph/TileData.h index e3efc33f..2750c4af 100644 --- a/inc/hgl/graph/TileData.h +++ b/inc/hgl/graph/TileData.h @@ -12,13 +12,15 @@ namespace hgl { namespace graph { + class TextureManager; + /** * TileData是一种处理大量等同尺寸及格式贴图的管理机制,程序会自动根据显卡最大贴图处理能力来创建尽可能符合需求的贴图。(注:Tile的大小不必符合2次幂) * Tile的增加或删除,程序会自动排序,尽可能小的减少I/O消耗。 */ class TileData ///Tile纹理管理 { - GPUDevice *device; + TextureManager *texture_manager; protected: @@ -52,7 +54,7 @@ namespace hgl public: - TileData(GPUDevice *,Texture2D *,const uint tw,const uint th); + TileData(TextureManager *,Texture2D *,const uint tw,const uint th); virtual ~TileData(); void BeginCommit(); diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index fef6cf45..0bce63d4 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -198,12 +198,6 @@ public: RenderTarget *CreateRT( const FramebufferInfo *fbi,RenderPass *,const uint32_t fence_count=1); RenderTarget *CreateRT( const FramebufferInfo *fbi,const uint32_t fence_count=1); - -public: - - TileData *CreateTileData(const VkFormat video_format,const uint width,const uint height,const uint count); ///<创建一个Tile数据集 - - TileFont *CreateTileFont(FontSource *fs,int limit_count=-1); ///<创建一个Tile字体 };//class GPUDevice VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_DEVICE_INCLUDE diff --git a/inc/hgl/graph/VKRenderResource.h b/inc/hgl/graph/VKRenderResource.h index 46e62d62..fc95cc15 100644 --- a/inc/hgl/graph/VKRenderResource.h +++ b/inc/hgl/graph/VKRenderResource.h @@ -34,7 +34,6 @@ using DescriptorSetID =int; using PrimitiveID =int; using RenderableID =int; using SamplerID =int; -using TextureID =int; using StaticMeshID =int; class VertexAttribData; @@ -59,7 +58,6 @@ class RenderResource IDObjectManage rm_primitives; ///<图元合集 IDObjectManage rm_buffers; ///<顶点缓冲区合集 IDObjectManage rm_samplers; ///<采样器合集 - IDObjectManage rm_textures; ///<纹理合集 IDObjectManage rm_renderables; ///<渲染实例集合集 IDObjectManage rm_static_mesh; ///<静态网格合集 @@ -105,7 +103,7 @@ public: //添加数据到管理器(如果指针为nullptr会返回-1) PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);} BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);} SamplerID Add(Sampler * s ){return rm_samplers.Add(s);} - TextureID Add(Texture * t ){return rm_textures.Add(t);} +// TextureID Add(Texture * t ){return rm_textures.Add(t);} RenderableID Add(Renderable * r ){return rm_renderables.Add(r);} StaticMeshID Add(StaticMesh * sm ){return rm_static_mesh.Add(sm);} @@ -175,7 +173,7 @@ public: //Get Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);} DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);} Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);} - Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);} +// Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);} Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);} StaticMesh * GetStaticMesh (const StaticMeshID &id){return rm_static_mesh.Get(id);} @@ -188,7 +186,7 @@ public: //Release void Release(Primitive * p ){rm_primitives.Release(p);} void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);} void Release(Sampler * s ){rm_samplers.Release(s);} - void Release(Texture * t ){rm_textures.Release(t);} +// void Release(Texture * t ){rm_textures.Release(t);} void Release(Renderable * r ){rm_renderables.Release(r);} void Release(StaticMesh * sm ){rm_static_mesh.Release(sm);} diff --git a/inc/hgl/graph/VKTexture.h b/inc/hgl/graph/VKTexture.h index a322af3f..67884fbb 100644 --- a/inc/hgl/graph/VKTexture.h +++ b/inc/hgl/graph/VKTexture.h @@ -15,11 +15,15 @@ class Texture { protected: + TextureManager *manager; + VkDevice device; TextureData *data; public: + TextureManager * GetManager () {return manager;} + TextureData * GetData () {return data;} VkDeviceMemory GetDeviceMemory () {return data?(data->memory?data->memory->operator VkDeviceMemory():VK_NULL_HANDLE):VK_NULL_HANDLE;} @@ -40,9 +44,9 @@ public: public: - Texture(VkDevice dev,TextureData *td) + Texture(TextureManager *tm,TextureData *td) { - device=dev; + manager=tm; data=td; } @@ -95,7 +99,7 @@ class TextureCube:public Texture { public: - TextureCube(VkDevice dev,TextureData *td):Texture(dev,td){} + using Texture::Texture; ~TextureCube()=default; static VkImageViewType GetImageViewType(){return VK_IMAGE_VIEW_TYPE_CUBE;} diff --git a/inc/hgl/graph/font/TextPrimitive.h b/inc/hgl/graph/font/TextPrimitive.h index 7bad2791..38faceec 100644 --- a/inc/hgl/graph/font/TextPrimitive.h +++ b/inc/hgl/graph/font/TextPrimitive.h @@ -24,10 +24,10 @@ namespace hgl friend class TextLayout; friend class TextRender; - SortedSets chars_sets; + SortedSet chars_sets; - const SortedSets &GetCharsSets()const{return chars_sets;} - void SetCharsSets(const SortedSets &sl){chars_sets=sl;} + const SortedSet &GetCharsSets()const{return chars_sets;} + void SetCharsSets(const SortedSet &sl){chars_sets=sl;} void ClearCharsSets(){chars_sets.Clear();} private: diff --git a/inc/hgl/graph/manager/TextureManager.h b/inc/hgl/graph/manager/TextureManager.h index 50a77d3d..7bd8381c 100644 --- a/inc/hgl/graph/manager/TextureManager.h +++ b/inc/hgl/graph/manager/TextureManager.h @@ -1,16 +1,22 @@ #pragma once #include -#include +#include #include #include +#include #include VK_NAMESPACE_BEGIN +using TextureID =int; + class TextureManager:public GraphManager { - SortedSets texture_list; + SortedSet image_set; + SortedSet texture_set; ///<纹理合集 + +private: DeviceQueue *texture_queue; TextureCmdBuffer *texture_cmd_buf; @@ -20,11 +26,13 @@ public: TextureManager(); virtual ~TextureManager(); -public: //Buffer +private: //Buffer DeviceBuffer *CreateTransferSourceBuffer(const VkDeviceSize,const void *data_ptr=nullptr); -public: //Image + friend class TileData; + +private: //Image VkImage CreateImage (VkImageCreateInfo *); void DestroyImage (VkImage); @@ -80,6 +88,9 @@ public: //Create/Chagne bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); bool ChangeTexture2DArray(Texture2DArray *,const void *data,const VkDeviceSize size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); +public: + + void Release(Texture *); };//class TextureManager VK_NAMESPACE_END diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index a012812b..02f33b2c 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -139,8 +139,10 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h Vulkan/VKArrayBuffer.cpp ) -SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h - Vulkan/Texture/GenMipmaps.cpp +SET(VK_IMAGE_SOURCE Vulkan/Texture/BufferImageCopy2D.h + Vulkan/VKDeviceImage.cpp) + +SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/GenMipmaps.cpp Vulkan/Texture/VKTexture.cpp Vulkan/Texture/VKTexture2D.cpp Vulkan/Texture/VKTexture2DArray.cpp @@ -153,15 +155,14 @@ SET(VK_TEXTURE_LOADER_SOURCE ${SG_INCLUDE_PATH}/VKTextureCreateInfo.h Vulkan/Texture/VKTextureCubeLoader.cpp) SET(VK_DEVICE_CREATER_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h - ${SG_INCLUDE_PATH}/VKDeviceAttribute.h - ${SG_INCLUDE_PATH}/VKDeviceCreater.h - Vulkan/VKDeviceAttribute.cpp - Vulkan/VKDeviceCreater.cpp - Vulkan/VKDevice.cpp) - + ${SG_INCLUDE_PATH}/VKDeviceAttribute.h + ${SG_INCLUDE_PATH}/VKDeviceCreater.h + Vulkan/VKDeviceAttribute.cpp + Vulkan/VKDeviceCreater.cpp + Vulkan/VKDevice.cpp) + SET(VK_DEVICE_SOURCE Vulkan/VKDeviceMemory.cpp Vulkan/VKDeviceBuffer.cpp - Vulkan/VKDeviceImage.cpp Vulkan/VKDeviceSampler.cpp Vulkan/VKDeviceMaterial.cpp Vulkan/VKDeviceFramebuffer.cpp @@ -182,8 +183,9 @@ SOURCE_GROUP("Vulkan\\Device\\Debug" FILES ${VK_DEBUG_SOURCE}) SOURCE_GROUP("Vulkan\\Device\\Instance" FILES ${VK_INST_SOURCE}) SOURCE_GROUP("Vulkan\\Device\\Physical Device" FILES ${VK_PHYSICAL_DEVICE_SOURCE}) SOURCE_GROUP("Vulkan\\Device\\Memory" FILES ${VK_MEMORY_SOURCE}) -SOURCE_GROUP("Vulkan\\Device\\Texture" FILES ${VK_DEVICE_TEXTURE_SOURCE}) -SOURCE_GROUP("Vulkan\\Device\\Texture\\Loader" FILES ${VK_TEXTURE_LOADER_SOURCE}) +SOURCE_GROUP("Vulkan\\Texture" FILES ${VK_DEVICE_TEXTURE_SOURCE}) +SOURCE_GROUP("Vulkan\\Texture\\Loader" FILES ${VK_TEXTURE_LOADER_SOURCE}) +SOURCE_GROUP("Vulkan\\Texture\\Image" FILES ${VK_IMAGE_SOURCE}) SET(VK_DESCRIPTOR_SETS_SOURCE ${SG_INCLUDE_PATH}/VKDescriptorSet.h Vulkan/VKDescriptorSet.cpp @@ -356,6 +358,7 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE} ${VK_PHYSICAL_DEVICE_SOURCE} ${VK_DESCRIPTOR_SETS_SOURCE} ${VK_SHADER_SOURCE} + ${VK_IMAGE_SOURCE} ${VK_TEXTURE_SOURCE} ${VK_MATERIAL_SOURCE} ${VK_RENDER_PASS_SOURCE} diff --git a/src/SceneGraph/TileData.cpp b/src/SceneGraph/TileData.cpp index aab8cb28..5b983a76 100644 --- a/src/SceneGraph/TileData.cpp +++ b/src/SceneGraph/TileData.cpp @@ -2,14 +2,15 @@ #include #include #include +#include namespace hgl { namespace graph { - TileData::TileData(GPUDevice *dev,Texture2D *tt,const uint tw,const uint th) + TileData::TileData(TextureManager *tm,Texture2D *tt,const uint tw,const uint th) { - device=dev; + texture_manager=tm; tile_texture=tt; @@ -52,7 +53,7 @@ namespace hgl tile_bytes=GetImageBytes(tile_texture->GetFormat(),tile_width*tile_height); - tile_buffer=device->CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,tile_bytes*tile_max_count,nullptr); + tile_buffer=texture_manager->CreateTransferSourceBuffer(tile_bytes*tile_max_count); commit_ptr=nullptr; } @@ -79,7 +80,7 @@ namespace hgl tile_buffer->Unmap(); commit_ptr=nullptr; - if(!device->ChangeTexture2D(tile_texture,tile_buffer,commit_list)) + if(!texture_manager->ChangeTexture2D(tile_texture,tile_buffer,commit_list)) return -2; const int result=commit_list.GetCount(); diff --git a/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp b/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp index a6fbf1a5..74a6c605 100644 --- a/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp +++ b/src/SceneGraph/Vulkan/Texture/VKTexture2D.cpp @@ -13,7 +13,11 @@ Texture2D *TextureManager::CreateTexture2D(TextureData *tex_data) if(!tex_data) return(nullptr); - return(new Texture2D(GetVkDevice(),tex_data)); + Texture2D *tex=new Texture2D(GetVkDevice(),tex_data); + + texture_set.Add(tex); + + return tex; } Texture2D *TextureManager::CreateTexture2D(TextureCreateInfo *tci) diff --git a/src/SceneGraph/Vulkan/VKDeviceImage.cpp b/src/SceneGraph/Vulkan/VKDeviceImage.cpp index 9127eaf8..4026eb3e 100644 --- a/src/SceneGraph/Vulkan/VKDeviceImage.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceImage.cpp @@ -13,6 +13,8 @@ VkImage TextureManager::CreateImage(VkImageCreateInfo *ici) if(vkCreateImage(GetVkDevice(),ici, nullptr, &image)!=VK_SUCCESS) return(nullptr); + image_set.Add(image); + return image; } @@ -20,6 +22,11 @@ void TextureManager::DestroyImage(VkImage img) { if(img==VK_NULL_HANDLE)return; + if(!image_set.Contains(img)) + return; + + image_set.Delete(img); + vkDestroyImage(GetVkDevice(),img,nullptr); } VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKTexture.cpp b/src/SceneGraph/Vulkan/VKTexture.cpp index b8cbe216..af541e52 100644 --- a/src/SceneGraph/Vulkan/VKTexture.cpp +++ b/src/SceneGraph/Vulkan/VKTexture.cpp @@ -1,11 +1,14 @@ #include #include #include +#include VK_NAMESPACE_BEGIN Texture::~Texture() { if(!data)return; + manager->Release(this); + if(data->image_view) delete data->image_view; diff --git a/src/SceneGraph/Vulkan/VKTileData.cpp b/src/SceneGraph/Vulkan/VKTileData.cpp index 9cea3f83..c7e38ab8 100644 --- a/src/SceneGraph/Vulkan/VKTileData.cpp +++ b/src/SceneGraph/Vulkan/VKTileData.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include namespace { @@ -61,7 +63,7 @@ namespace }//namespace VK_NAMESPACE_BEGIN -TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count) +TileData *RenderFramework::CreateTileData(const VkFormat format,const uint width,const uint height,const uint count) { if(!CheckVulkanFormat(format)) return(nullptr); @@ -69,7 +71,7 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const if(width<=0||height<=0||count<=0) return(nullptr); - const uint32_t max_2d_texture=attr->physical_device->GetMaxImage2D(); + const uint32_t max_2d_texture=device->GetPhysicalDevice()->GetMaxImage2D(); uint tex_width,tex_height; @@ -84,16 +86,16 @@ TileData *GPUDevice::CreateTileData(const VkFormat format,const uint width,const if(RangeCheck(vf->color)) { - tex=CreateTexture2D(new ColorTextureCreateInfo(format,extent)); + tex=texture_manager->CreateTexture2D(new ColorTextureCreateInfo(format,extent)); } else if(RangeCheck(vf->depth)) { - tex=CreateTexture2D(new DepthTextureCreateInfo(format,extent)); + tex=texture_manager->CreateTexture2D(new DepthTextureCreateInfo(format,extent)); } else return(nullptr); - return(new TileData(this,tex,width,height)); + return(new TileData(texture_manager,tex,width,height)); } VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKTileFont.cpp b/src/SceneGraph/Vulkan/VKTileFont.cpp index bfabc10a..6df1822b 100644 --- a/src/SceneGraph/Vulkan/VKTileFont.cpp +++ b/src/SceneGraph/Vulkan/VKTileFont.cpp @@ -7,7 +7,7 @@ VK_NAMESPACE_BEGIN * @param f 字体需求信息 * @param limit_count 缓冲字符数量上限 */ -TileFont *GPUDevice::CreateTileFont(FontSource *fs,int limit_count) +TileFont *RenderFramework::CreateTileFont(FontSource *fs,int limit_count) { if(!fs)return(nullptr); diff --git a/src/SceneGraph/manager/TextureManager.cpp b/src/SceneGraph/manager/TextureManager.cpp index e69de29b..917c71a7 100644 --- a/src/SceneGraph/manager/TextureManager.cpp +++ b/src/SceneGraph/manager/TextureManager.cpp @@ -0,0 +1,13 @@ +#include + +VK_NAMESPACE_BEGIN + +void TextureManager::Release(Texture *tex) +{ + if(!tex) + return; + + texture_set.Delete(tex); +} + +VK_NAMESPACE_END