diff --git a/CMCore b/CMCore index c22207b6..109e52db 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit c22207b6401476bf8859e581a28346326e6d482b +Subproject commit 109e52db4da1c88a30ecb33e121f9ac06fcab397 diff --git a/example/common/VulkanAppFramework.h b/example/common/VulkanAppFramework.h index 3650536b..e4961b64 100644 --- a/example/common/VulkanAppFramework.h +++ b/example/common/VulkanAppFramework.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/inc/hgl/graph/SceneTreeToRenderList.h b/inc/hgl/graph/SceneTreeToRenderList.h index d197cab3..a27fc4cf 100644 --- a/inc/hgl/graph/SceneTreeToRenderList.h +++ b/inc/hgl/graph/SceneTreeToRenderList.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include using RenderNodePointer=hgl::graph::RenderNode *; diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 84be6bfa..54fdb609 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -54,7 +54,21 @@ class RenderPass; class GPUFence; class GPUSemaphore; +enum class DescriptorSetsType +{ + //设计使其对应shader中的sets + + Material=0, ///<材质中永远不变的参数 +// Texture, ///<材质中的纹理参数 + Values, ///<材质中的变量参数 + Renderable, ///<渲染实例参数(如Local2World matrix) + Global, ///<全局参数(如太阳光等) + + ENUM_CLASS_RANGE(Material,Global) +};// + class DescriptorSetLayoutCreater; +class DescriptorSets; struct ShaderStage; @@ -67,7 +81,6 @@ class PipelineLayout; struct PipelineData; enum class InlinePipeline; class Pipeline; -class DescriptorSets; class VertexAttributeBinding; class Renderable; diff --git a/inc/hgl/graph/VKMaterial.h b/inc/hgl/graph/VKMaterial.h index fa40d263..c1a48942 100644 --- a/inc/hgl/graph/VKMaterial.h +++ b/inc/hgl/graph/VKMaterial.h @@ -23,8 +23,7 @@ class Material DescriptorSetLayoutCreater *dsl_creater; - DescriptorSets *g_desc_sets; - DescriptorSets *ri_desc_sets; + MaterialParameters *mp_m,*mp_g,*mp_r; VertexAttributeBinding *vab; @@ -63,11 +62,7 @@ public: const VkPipelineShaderStageCreateInfo * GetStages ()const{return shader_stage_list->GetData();} const VkPipelineLayout GetPipelineLayout ()const; - DescriptorSets * CreateMIDescriptorSets ()const; - - DescriptorSets * GetGlobalDescriptorSets (){return g_desc_sets;} - DescriptorSets * GetRIDescriptorSets (){return ri_desc_sets;} - + const VertexAttributeBinding * GetVAB ()const{return vab;} const uint32_t GetVertexAttrCount ()const{return vab->GetVertexAttrCount();} const VkVertexInputBindingDescription * GetVertexBindingList ()const{return vab->GetVertexBindingList();} @@ -75,7 +70,14 @@ public: public: - MaterialParameters * CreateInstance (); + MaterialParameters * CreateMP (const DescriptorSetsType &type=DescriptorSetsType::Values); + MaterialParameters * GetMP (const DescriptorSetsType &type) + { + if(type==DescriptorSetsType::Material )return mp_m;else + if(type==DescriptorSetsType::Renderable )return mp_r;else + if(type==DescriptorSetsType::Global )return mp_g;else + return(nullptr); + } };//class Material VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE diff --git a/inc/hgl/graph/VKMaterialInstance.h b/inc/hgl/graph/VKMaterialParameters.h similarity index 97% rename from inc/hgl/graph/VKMaterialInstance.h rename to inc/hgl/graph/VKMaterialParameters.h index d5a29023..910cf522 100644 --- a/inc/hgl/graph/VKMaterialInstance.h +++ b/inc/hgl/graph/VKMaterialParameters.h @@ -28,7 +28,7 @@ public: #define MP_TYPE_IS(name) const bool is##name()const{return ds_type==DescriptorSetsType::name;} MP_TYPE_IS(Material) - MP_TYPE_IS(Texture) +// MP_TYPE_IS(Texture) MP_TYPE_IS(Values) MP_TYPE_IS(Renderable) MP_TYPE_IS(Global) diff --git a/inc/hgl/graph/VKRenderResource.h b/inc/hgl/graph/VKRenderResource.h index e2750c55..50108ee1 100644 --- a/inc/hgl/graph/VKRenderResource.h +++ b/inc/hgl/graph/VKRenderResource.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/inc/hgl/graph/VKRenderTarget.h b/inc/hgl/graph/VKRenderTarget.h index 77075ceb..0ce89764 100644 --- a/inc/hgl/graph/VKRenderTarget.h +++ b/inc/hgl/graph/VKRenderTarget.h @@ -55,11 +55,11 @@ public: public: //pipeline Pipeline *CreatePipeline(Material *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false); - Pipeline *CreatePipeline(MaterialInstance *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false); + Pipeline *CreatePipeline(MaterialParameters *, const InlinePipeline &, const Prim &prim=Prim::Triangles,const bool prim_restart=false); Pipeline *CreatePipeline(Material *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false); - Pipeline *CreatePipeline(MaterialInstance *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false); + Pipeline *CreatePipeline(MaterialParameters *, PipelineData *, const Prim &prim=Prim::Triangles,const bool prim_restart=false); Pipeline *CreatePipeline(Material *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false); - Pipeline *CreatePipeline(MaterialInstance *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false); + Pipeline *CreatePipeline(MaterialParameters *, const OSString &, const Prim &prim=Prim::Triangles,const bool prim_restart=false); public: // command buffer diff --git a/inc/hgl/graph/VKRenderableInstance.h b/inc/hgl/graph/VKRenderableInstance.h index 54ab07f2..1bd81ad8 100644 --- a/inc/hgl/graph/VKRenderableInstance.h +++ b/inc/hgl/graph/VKRenderableInstance.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include VK_NAMESPACE_BEGIN /** * 可渲染对象实例
diff --git a/inc/hgl/graph/shader/ShaderResource.h b/inc/hgl/graph/shader/ShaderResource.h index 123f4d62..f7493d27 100644 --- a/inc/hgl/graph/shader/ShaderResource.h +++ b/inc/hgl/graph/shader/ShaderResource.h @@ -7,25 +7,6 @@ VK_NAMESPACE_BEGIN -/** - * Shader数据来源 - */ -enum class ShaderDataSource -{ - Global=0, ///<由全局系统提供的数据(如CameraMatrix) - Private=1, ///<每种材质的私有数据 -};// - -/** - * Shader数据来源类型 - */ -enum class ShaderDataSourceType -{ - Static=0, - Dynamic, - Instance -}; - struct ShaderStage { AnsiString name; @@ -51,17 +32,6 @@ struct ShaderDescriptor using ShaderDescriptorList=List; -enum class DescriptorSetsType -{ - //设计使其对应shader中的sets - - Material=0, ///<材质中永远不变的参数 - Texture, ///<材质中的纹理参数 - Values, ///<材质中的变量参数 - Renderable, ///<渲染实例参数(如Local2World matrix) - Global, ///<全局参数(如太阳光等) -};// - #ifndef VK_DESCRIPTOR_TYPE_BEGIN_RANGE constexpr size_t VK_DESCRIPTOR_TYPE_BEGIN_RANGE=VK_DESCRIPTOR_TYPE_SAMPLER; #endif//VK_DESCRIPTOR_TYPE_BEGIN_RANGE diff --git a/src/GUI/DefaultThemeEngine.h b/src/GUI/DefaultThemeEngine.h index 9e76b262..ca240d0b 100644 --- a/src/GUI/DefaultThemeEngine.h +++ b/src/GUI/DefaultThemeEngine.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include"DefaultThemeForm.h" diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 46731c0e..96259eba 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -122,6 +122,7 @@ SET(VK_DEVICE_SOURCE ${SG_INCLUDE_PATH}/VKDevice.h Vulkan/VKDeviceBuffer.cpp Vulkan/VKDeviceImage.cpp Vulkan/VKDeviceTexture.cpp + Vulkan/VKDeviceMaterial.cpp Vulkan/VKDeviceFramebuffer.cpp Vulkan/VKDeviceSwapchain.cpp Vulkan/VKDeviceRenderPass.cpp @@ -159,9 +160,9 @@ SET(VK_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/VKImageView.h Vulkan/VKTextureLoader.cpp) SET(VK_MATERIAL_SOURCE ${SG_INCLUDE_PATH}/VKMaterial.h - ${SG_INCLUDE_PATH}/VKMaterialInstance.h + ${SG_INCLUDE_PATH}/VKMaterialParameters.h Vulkan/VKMaterial.cpp - Vulkan/VKMaterialInstance.cpp) + Vulkan/VKMaterialParameters.cpp) SOURCE_GROUP("Vulkan\\Material" FILES ${VK_MATERIAL_SOURCE}) SOURCE_GROUP("Vulkan\\Material\\Texture" FILES ${VK_TEXTURE_SOURCE}) diff --git a/src/SceneGraph/RenderList.cpp b/src/SceneGraph/RenderList.cpp index cf892bce..9f9770de 100644 --- a/src/SceneGraph/RenderList.cpp +++ b/src/SceneGraph/RenderList.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace hgl diff --git a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp index 51ab40b9..c6f64b9e 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp +++ b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.cpp @@ -35,8 +35,7 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc { //重复的绑定点是有可能存在的,比如CameraInfo在vs/fs中同时存在 - if((!index_by_binding.KeyExist(sd.binding)) - &&(!index_by_binding_ri.KeyExist(sd.binding))) + if(!all_index_by_binding.KeyExist(sd.binding)) { p->binding = sd.binding; p->descriptorType = desc_type; @@ -45,15 +44,16 @@ void DescriptorSetLayoutCreater::Bind(const ShaderDescriptorList *sd_list,VkDesc p->pImmutableSamplers = nullptr; if(sd.name[0]=='r' - &&sd.name[1]=='i' - &&sd.name[2]=='_') - index_by_binding_ri.Add(sd.binding,fin_count+old_count); + &&sd.name[1]=='_') + index_by_binding[(size_t)DescriptorSetsType::Renderable].Add(sd.binding,fin_count+old_count); else if(sd.name[0]=='g' &&sd.name[1]=='_') - index_by_binding_global.Add(sd.binding,fin_count+old_count); + index_by_binding[(size_t)DescriptorSetsType::Global].Add(sd.binding,fin_count+old_count); else - index_by_binding.Add(sd.binding,fin_count+old_count); + index_by_binding[(size_t)DescriptorSetsType::Values].Add(sd.binding,fin_count+old_count); + + all_index_by_binding.Add(sd.binding,fin_count+old_count); ++p; ++fin_count; @@ -113,14 +113,15 @@ DescriptorSets *DescriptorSetLayoutCreater::Create(const DescriptorSetsType &typ BindingMapping *bm=nullptr; if(type==DescriptorSetsType::Material - ||type==DescriptorSetsType::MaterialInstance) //未开会区分开 - bm=&index_by_binding; +// ||type==DescriptorSetsType::Texture + ||type==DescriptorSetsType::Values) //未来会区分开 + bm=&index_by_binding[(size_t)DescriptorSetsType::Values]; else - if(type==DescriptorSetsType::RenderableInstance) - bm=&index_by_binding_ri; + if(type==DescriptorSetsType::Renderable) + bm=&index_by_binding[(size_t)DescriptorSetsType::Renderable]; else if(type==DescriptorSetsType::Global) - bm=&index_by_binding_global; + bm=&index_by_binding[(size_t)DescriptorSetsType::Global]; else return(nullptr); diff --git a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h index d4a2a890..9efb4714 100644 --- a/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h +++ b/src/SceneGraph/Vulkan/VKDescriptorSetLayoutCreater.h @@ -17,9 +17,8 @@ class DescriptorSetLayoutCreater List layout_binding_list; VkDescriptorSetLayout dsl=VK_NULL_HANDLE; - BindingMapping index_by_binding; - BindingMapping index_by_binding_ri; - BindingMapping index_by_binding_global; + BindingMapping all_index_by_binding; + BindingMapping index_by_binding[size_t(DescriptorSetsType::RANGE_SIZE)]; VkPipelineLayout pipeline_layout=VK_NULL_HANDLE; diff --git a/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp b/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp new file mode 100644 index 00000000..7b595f22 --- /dev/null +++ b/src/SceneGraph/Vulkan/VKDeviceMaterial.cpp @@ -0,0 +1,83 @@ +#include +#include +#include"VKDescriptorSetLayoutCreater.h" + +VK_NAMESPACE_BEGIN +Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps) +{ + const int shader_count=shader_maps->GetCount(); + + if(shader_count<2) + return(nullptr); + + const ShaderModule *sm; + + if(!shader_maps->Get(VK_SHADER_STAGE_VERTEX_BIT,sm)) + return(nullptr); + + DescriptorSetLayoutCreater *dsl_creater=CreateDescriptorSetLayoutCreater(); + List *shader_stage_list=new List; + + shader_stage_list->SetCount(shader_count); + + VkPipelineShaderStageCreateInfo *p=shader_stage_list->GetData(); + + auto **itp=shader_maps->GetDataList(); + for(int i=0;iright; + hgl_cpy(p,sm->GetCreateInfo()); + + dsl_creater->Bind(sm->GetDescriptorList(),sm->GetStage()); + + ++p; + ++itp; + } + + if(!dsl_creater->CreatePipelineLayout()) + { + delete shader_stage_list; + delete dsl_creater; + delete shader_maps; + return(nullptr); + } + + return(new Material(mtl_name,shader_maps,shader_stage_list,dsl_creater)); +} + +Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module) +{ + if(!vertex_shader_module||!fragment_shader_module) + return(nullptr); + + if(!vertex_shader_module->IsVertex())return(nullptr); + if(!fragment_shader_module->IsFragment())return(nullptr); + + ShaderModuleMap *smm=new ShaderModuleMap; + + smm->Add(vertex_shader_module); + smm->Add(fragment_shader_module); + + return CreateMaterial(mtl_name,smm); +} + +Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module) +{ + if(!vertex_shader_module + ||!geometry_shader_module + ||!fragment_shader_module) + return(nullptr); + + if(!vertex_shader_module->IsVertex())return(nullptr); + if(!geometry_shader_module->IsGeometry())return(nullptr); + if(!fragment_shader_module->IsFragment())return(nullptr); + + ShaderModuleMap *smm=new ShaderModuleMap; + + smm->Add(vertex_shader_module); + smm->Add(geometry_shader_module); + smm->Add(fragment_shader_module); + + return CreateMaterial(mtl_name,smm); +} +VK_NAMESPACE_END \ No newline at end of file diff --git a/src/SceneGraph/Vulkan/VKMaterial.cpp b/src/SceneGraph/Vulkan/VKMaterial.cpp index a28681fa..14e0c280 100644 --- a/src/SceneGraph/Vulkan/VKMaterial.cpp +++ b/src/SceneGraph/Vulkan/VKMaterial.cpp @@ -1,90 +1,7 @@ #include -#include -#include -#include -#include -#include -#include +#include #include"VKDescriptorSetLayoutCreater.h" VK_NAMESPACE_BEGIN -Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *shader_maps) -{ - const int shader_count=shader_maps->GetCount(); - - if(shader_count<2) - return(nullptr); - - const ShaderModule *sm; - - if(!shader_maps->Get(VK_SHADER_STAGE_VERTEX_BIT,sm)) - return(nullptr); - - DescriptorSetLayoutCreater *dsl_creater=CreateDescriptorSetLayoutCreater(); - List *shader_stage_list=new List; - - shader_stage_list->SetCount(shader_count); - - VkPipelineShaderStageCreateInfo *p=shader_stage_list->GetData(); - - auto **itp=shader_maps->GetDataList(); - for(int i=0;iright; - hgl_cpy(p,sm->GetCreateInfo()); - - dsl_creater->Bind(sm->GetDescriptorList(),sm->GetStage()); - - ++p; - ++itp; - } - - if(!dsl_creater->CreatePipelineLayout()) - { - delete shader_stage_list; - delete dsl_creater; - delete shader_maps; - return(nullptr); - } - - return(new Material(mtl_name,shader_maps,shader_stage_list,dsl_creater)); -} - -Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *fragment_shader_module) -{ - if(!vertex_shader_module||!fragment_shader_module) - return(nullptr); - - if(!vertex_shader_module->IsVertex())return(nullptr); - if(!fragment_shader_module->IsFragment())return(nullptr); - - ShaderModuleMap *smm=new ShaderModuleMap; - - smm->Add(vertex_shader_module); - smm->Add(fragment_shader_module); - - return CreateMaterial(mtl_name,smm); -} - -Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,const VertexShaderModule *vertex_shader_module,const ShaderModule *geometry_shader_module,const ShaderModule *fragment_shader_module) -{ - if(!vertex_shader_module - ||!geometry_shader_module - ||!fragment_shader_module) - return(nullptr); - - if(!vertex_shader_module->IsVertex())return(nullptr); - if(!geometry_shader_module->IsGeometry())return(nullptr); - if(!fragment_shader_module->IsFragment())return(nullptr); - - ShaderModuleMap *smm=new ShaderModuleMap; - - smm->Add(vertex_shader_module); - smm->Add(geometry_shader_module); - smm->Add(fragment_shader_module); - - return CreateMaterial(mtl_name,smm); -} - Material::Material(const UTF8String &name,ShaderModuleMap *smm,List *psci_list,DescriptorSetLayoutCreater *dslc) { mtl_name=name; @@ -105,12 +22,17 @@ Material::Material(const UTF8String &name,ShaderModuleMap *smm,ListCreate(DescriptorSetsType::RenderableInstance); + mp_m=CreateMP(DescriptorSetsType::Material); + mp_r=CreateMP(DescriptorSetsType::Renderable); + mp_g=CreateMP(DescriptorSetsType::Global); } Material::~Material() { - SAFE_CLEAR(ri_desc_sets); + SAFE_CLEAR(mp_m); + SAFE_CLEAR(mp_r); + SAFE_CLEAR(mp_g); + delete dsl_creater; if(vab) @@ -153,8 +75,12 @@ const VkPipelineLayout Material::GetPipelineLayout()const return dsl_creater->GetPipelineLayout(); } -DescriptorSets *Material::CreateMIDescriptorSets()const +MaterialParameters *Material::CreateMP(const DescriptorSetsType &type) { - return dsl_creater->Create(DescriptorSetsType::MaterialInstance); + DescriptorSets *ds=dsl_creater->Create(type); + + if(!ds)return(nullptr); + + return(new MaterialParameters(this,type,ds)); } VK_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKMaterialInstance.cpp b/src/SceneGraph/Vulkan/VKMaterialParameters.cpp similarity index 81% rename from src/SceneGraph/Vulkan/VKMaterialInstance.cpp rename to src/SceneGraph/Vulkan/VKMaterialParameters.cpp index c69a270b..e12b5d18 100644 --- a/src/SceneGraph/Vulkan/VKMaterialInstance.cpp +++ b/src/SceneGraph/Vulkan/VKMaterialParameters.cpp @@ -1,12 +1,13 @@ -#include +#include #include #include VK_NAMESPACE_BEGIN -MaterialParameters::MaterialParameters(Material *m,DescriptorSets *ds) +MaterialParameters::MaterialParameters(Material *m,const DescriptorSetsType &type,DescriptorSets *ds) { material=m; + ds_type=type; descriptor_sets=ds; } @@ -67,13 +68,4 @@ void MaterialParameters::Update() { descriptor_sets->Update(); } - -MaterialParameters *Material::CreateInstance() -{ - DescriptorSets *ds=CreateMIDescriptorSets(); - - if(!ds)return(nullptr); - - return(new MaterialParameters(this,ds)); -} VK_NAMESPACE_END \ No newline at end of file diff --git a/src/SceneGraph/Vulkan/VKRenderResource.cpp b/src/SceneGraph/Vulkan/VKRenderResource.cpp index ddc79bc6..0cafdec5 100644 --- a/src/SceneGraph/Vulkan/VKRenderResource.cpp +++ b/src/SceneGraph/Vulkan/VKRenderResource.cpp @@ -54,7 +54,7 @@ MaterialParameters *RenderResource::CreateMaterialInstance(Material *mtl) { if(!mtl)return(nullptr); - MaterialParameters *mi=mtl->CreateInstance(); + MaterialParameters *mi=mtl->CreateMP(); if(mi) Add(mi); diff --git a/src/SceneGraph/Vulkan/VKRenderTargetPipeline.cpp b/src/SceneGraph/Vulkan/VKRenderTargetPipeline.cpp index c7f3edea..1221ea3b 100644 --- a/src/SceneGraph/Vulkan/VKRenderTargetPipeline.cpp +++ b/src/SceneGraph/Vulkan/VKRenderTargetPipeline.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/SceneGraph/Vulkan/VKRenderableInstance.cpp b/src/SceneGraph/Vulkan/VKRenderableInstance.cpp index 0350deac..a8f28796 100644 --- a/src/SceneGraph/Vulkan/VKRenderableInstance.cpp +++ b/src/SceneGraph/Vulkan/VKRenderableInstance.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include