diff --git a/CMCore b/CMCore index 2f4a583b..b6ee9c81 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 2f4a583b9c6eb71b752deb3f85674feb22b3cd08 +Subproject commit b6ee9c816fee718275fa031e0af4b12bf41276bb diff --git a/CMSceneGraph b/CMSceneGraph index bcf08554..404d0d84 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit bcf085546059dab3776bb8aa520680169dbeb3d5 +Subproject commit 404d0d8478aceb1d952cf7e3dfcf8a1fedaa5124 diff --git a/GLSLCompiler.dll b/GLSLCompiler.dll index e48d90be..bc7e5267 100644 Binary files a/GLSLCompiler.dll and b/GLSLCompiler.dll differ diff --git a/inc/hgl/graph/VKMaterialDescriptorManager.h b/inc/hgl/graph/VKMaterialDescriptorManager.h index 8b228916..25d08114 100644 --- a/inc/hgl/graph/VKMaterialDescriptorManager.h +++ b/inc/hgl/graph/VKMaterialDescriptorManager.h @@ -2,15 +2,13 @@ #define HGL_GRAPH_VULKAN_MATERIAL_DESCRIPTOR_MANAGER_INCLUDE #include -#include +#include VK_NAMESPACE_BEGIN class MaterialDescriptorManager { UTF8String mtl_name; - bool set_has_desc[DESCRIPTOR_SET_TYPE_COUNT]; - Map binding_map[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; private: @@ -22,6 +20,7 @@ private: public: MaterialDescriptorManager(const UTF8String &,ShaderDescriptor *,const uint); + MaterialDescriptorManager(const UTF8String &,const ShaderDescriptorSetArray &); ~MaterialDescriptorManager(); const UTF8String &GetMaterialName()const{return mtl_name;} @@ -35,9 +34,7 @@ public: const DescriptorSetLayoutCreateInfo *GetDSLCI(const DescriptorSetType &type)const{return dsl_ci+size_t(type);} - //const ShaderDescriptorList &GetDescriptorList(const DescriptorSetType &type)const{return sd_list_by_set_type[size_t(type)];} - - const bool hasSet(const DescriptorSetType &type)const{return set_has_desc[size_t(type)];} + const bool hasSet(const DescriptorSetType &type)const{return dsl_ci[size_t(type)].bindingCount>0;} //!sd_list_by_set_type[size_t(type)].IsEmpty();} };//class MaterialDescriptorManager VK_NAMESPACE_END diff --git a/inc/hgl/shadergen/MaterialCreateInfo.h b/inc/hgl/shadergen/MaterialCreateInfo.h index 6ade6811..94be2259 100644 --- a/inc/hgl/shadergen/MaterialCreateInfo.h +++ b/inc/hgl/shadergen/MaterialCreateInfo.h @@ -57,5 +57,7 @@ public: bool AddSampler(const VkShaderStageFlagBits flag_bits,const DescriptorSetType set_type,const SamplerType &st,const AnsiString &name); bool CreateShader(); + + const MaterialDescriptorInfo &GetMDI()const{return mdm;} };//class MaterialCreateInfo SHADERGEN_NAMESPACE_END diff --git a/inc/hgl/shadergen/MaterialDescriptorInfo.h b/inc/hgl/shadergen/MaterialDescriptorInfo.h index 34a610e6..a42bb181 100644 --- a/inc/hgl/shadergen/MaterialDescriptorInfo.h +++ b/inc/hgl/shadergen/MaterialDescriptorInfo.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include #include @@ -15,22 +14,6 @@ SHADERGEN_NAMESPACE_BEGIN */ class MaterialDescriptorInfo { - struct ShaderDescriptorSet - { - DescriptorSetType set_type; - - int set; - int count; - - ObjectMap descriptor_map; - - public: - - ShaderDescriptor *AddDescriptor(VkShaderStageFlagBits ssb,ShaderDescriptor *new_sd); ///<添加一个描述符,如果它本身存在,则返回false - }; - - using ShaderDescriptorSetArray=ShaderDescriptorSet[DESCRIPTOR_SET_TYPE_COUNT]; - ShaderDescriptorSetArray desc_set_array; Map struct_map; @@ -68,6 +51,11 @@ public: void Resort(); //排序产生set号与binding号 + const ShaderDescriptorSetArray &Get()const + { + return desc_set_array; + } + const bool hasSet(const DescriptorSetType &type)const { return desc_set_array[size_t(type)].count>0; diff --git a/inc/hgl/shadergen/ShaderCreateInfoVertex.h b/inc/hgl/shadergen/ShaderCreateInfoVertex.h index 82de6c70..30f353c9 100644 --- a/inc/hgl/shadergen/ShaderCreateInfoVertex.h +++ b/inc/hgl/shadergen/ShaderCreateInfoVertex.h @@ -16,7 +16,5 @@ public: int AddInput(const graph::VAT &type,const AnsiString &name); int AddInput(const AnsiString &type,const AnsiString &name); - - const hgl::graph::ShaderAttributeArray &GetInput()const; }; SHADERGEN_NAMESPACE_END diff --git a/src/SceneGraph/Vulkan/VKMaterialDescriptorManager.cpp b/src/SceneGraph/Vulkan/VKMaterialDescriptorManager.cpp index 2caf6949..60e06cd7 100644 --- a/src/SceneGraph/Vulkan/VKMaterialDescriptorManager.cpp +++ b/src/SceneGraph/Vulkan/VKMaterialDescriptorManager.cpp @@ -18,54 +18,38 @@ MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,Shad if(sd_count<=0)return; - ShaderDescriptorList sd_list_by_desc_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; - - hgl_zero(set_has_desc); - - uint dslb_count=0; + ENUM_CLASS_FOR(DescriptorSetType,int,i) + { + dsl_ci[i].bindingCount=0; + dsl_ci[i].pBindings=nullptr; + } { - ENUM_CLASS_FOR(DescriptorSetType,int,i) + ShaderDescriptor *sp=sd_list; + + for(uint i=0;idesc_type)].Add(sp->name,sp->binding); + + ++dsl_ci[size_t(sp->set_type)].bindingCount; + + ++sp; } + } - { - ShaderDescriptor *sp=sd_list; - - for(uint i=0;idesc_type>=VK_DESCRIPTOR_TYPE_BEGIN_RANGE - &&sp->desc_type<=VK_DESCRIPTOR_TYPE_END_RANGE) - sd_list_by_desc_type[(size_t)sp->desc_type].Add(sp); - - binding_map[size_t(sp->desc_type)].Add(sp->name,sp->binding); - - ++dsl_ci[size_t(sp->set_type)].bindingCount; - - ++dslb_count; - - set_has_desc[size_t(sp->set_type)]=true; - - ++sp; - } - } - - all_dslb=new VkDescriptorSetLayoutBinding[dslb_count]; + all_dslb=new VkDescriptorSetLayoutBinding[sd_count]; + { VkDescriptorSetLayoutBinding *dsl_bind[DESCRIPTOR_SET_TYPE_COUNT]; VkDescriptorSetLayoutBinding *dslp=all_dslb; - { - ENUM_CLASS_FOR(DescriptorSetType,int,i) - if(dsl_ci[i].bindingCount>0) - { - dsl_ci[i].pBindings=dslp; - dsl_bind[i]=dslp; - dslp+=dsl_ci[i].bindingCount; - } - } + ENUM_CLASS_FOR(DescriptorSetType,int,i) + if(dsl_ci[i].bindingCount>0) + { + dsl_ci[i].pBindings=dslp; + dsl_bind[i]=dslp; + dslp+=dsl_ci[i].bindingCount; + } { ShaderDescriptor *sp=sd_list; @@ -82,6 +66,58 @@ MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,Shad } } +MaterialDescriptorManager::MaterialDescriptorManager(const UTF8String &name,const ShaderDescriptorSetArray &sds_array) +{ + mtl_name=name; + + uint sd_count=0; + + ENUM_CLASS_FOR(DescriptorSetType,int,i) + { + dsl_ci[i].bindingCount=sds_array[i].count; + dsl_ci[i].pBindings=nullptr; + + sd_count+=sds_array[i].count; + + } + + if(sd_count<=0)return; + + all_dslb=new VkDescriptorSetLayoutBinding[sd_count]; + + { + VkDescriptorSetLayoutBinding *dsl_bind[DESCRIPTOR_SET_TYPE_COUNT]; + VkDescriptorSetLayoutBinding *dslp=all_dslb; + + ENUM_CLASS_FOR(DescriptorSetType,int,i) + if(dsl_ci[i].bindingCount>0) + { + dsl_ci[i].pBindings=dslp; + dsl_bind[i]=dslp; + dslp+=dsl_ci[i].bindingCount; + } + + ENUM_CLASS_FOR(DescriptorSetType,int,i) + { + auto *sp=sds_array[i].descriptor_map.GetDataList(); + ShaderDescriptor *sd; + + for(int j=0;jright; + + binding_map[size_t(sd->desc_type)].Add(sd->name,sd->binding); + + WriteDescriptorSetLayoutBinding(dsl_bind[i],sd); + + ++dsl_bind[i]; + + ++sp; + } + } + } +} + MaterialDescriptorManager::~MaterialDescriptorManager() { delete[] all_dslb; diff --git a/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp b/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp index 2ca29d53..e9ad2dbe 100644 --- a/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp +++ b/src/SceneGraph/Vulkan/VKRenderResourceMaterial.cpp @@ -9,6 +9,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN @@ -224,7 +225,7 @@ Material *RenderResource::CreateMaterial(const hgl::shadergen::MaterialCreateInf if(sm) { if(smm->Add(sm)) - vertex_input=new VertexInput(vert->GetInput()); + vertex_input=new VertexInput(vert->sdm->GetShaderStageIO().input); } smm->Add(sm); @@ -252,6 +253,16 @@ Material *RenderResource::CreateMaterial(const hgl::shadergen::MaterialCreateInf smm->Add(sm); } + MaterialDescriptorManager *mdm=new MaterialDescriptorManager(mci->GetName(),mci->GetMDI().Get()); + Material *mtl=device->CreateMaterial(mci->GetName(),smm,mdm,vertex_input); + + if(!mtl) + { + delete mdm; + delete smm; + } + + return mtl; } VK_NAMESPACE_END diff --git a/src/ShaderGen/GLSLCompiler.cpp b/src/ShaderGen/GLSLCompiler.cpp index 16c7952b..effe5404 100644 --- a/src/ShaderGen/GLSLCompiler.cpp +++ b/src/ShaderGen/GLSLCompiler.cpp @@ -43,6 +43,9 @@ namespace glsl_compiler SPVData * (*CompileFromPath)(const uint32_t stage,const char *shader_filename, const CompileInfo *compile_info); void (*Free)(SPVData *); + + SPVParseData *(*ParseSPV)(SPVData *spv_data); + void (*FreeParseSPVData)(SPVParseData *); }; ExternalModule *gsi_module=nullptr; @@ -142,6 +145,17 @@ namespace glsl_compiler gsi->Free(spv_data); } + SPVParseData *ParseSPV(SPVData *spv_data) + { + return gsi?gsi->ParseSPV(spv_data):nullptr; + } + + void FreeSPVParse(SPVParseData *spv) + { + if(gsi&&spv) + gsi->FreeParseSPVData(spv); + } + SPVData *Compile(const uint32_t type,const char *source) { if(!gsi) diff --git a/src/ShaderGen/GLSLCompiler.h b/src/ShaderGen/GLSLCompiler.h index 1d256827..d651af7b 100644 --- a/src/ShaderGen/GLSLCompiler.h +++ b/src/ShaderGen/GLSLCompiler.h @@ -75,7 +75,10 @@ namespace glsl_compiler uint32_t *spv_data; uint32_t spv_length; + }; + struct SPVParseData + { ShaderStageIO stage_io; ShaderDescriptorResource resource; ShaderResourceData push_constant; @@ -92,5 +95,8 @@ namespace glsl_compiler SPVData * Compile (const uint32_t type,const char *source); void Free (SPVData *spv_data); + + SPVParseData * ParseSPV(SPVData *spv_data); + void FreeSPVParse(SPVParseData *spv); }//namespace glsl_compiler #endif//HGL_GLSL_COMPILER_INCLUDE diff --git a/src/ShaderGen/MaterialDescriptorInfo.cpp b/src/ShaderGen/MaterialDescriptorInfo.cpp index e1773ab1..4b582d19 100644 --- a/src/ShaderGen/MaterialDescriptorInfo.cpp +++ b/src/ShaderGen/MaterialDescriptorInfo.cpp @@ -25,32 +25,6 @@ const DescriptorSetType MaterialDescriptorInfo::GetSetType(const AnsiString &nam return DescriptorSetType::Global; } -/** -* 添加一个描述符,如果它本身存在,则返回false -*/ -ShaderDescriptor *MaterialDescriptorInfo::ShaderDescriptorSet::AddDescriptor(VkShaderStageFlagBits ssb,ShaderDescriptor *new_sd) -{ - ShaderDescriptor *sd; - - if(descriptor_map.Get(new_sd->name,sd)) - { - delete new_sd; - sd->stage_flag|=ssb; - return(sd); - } - else - { - new_sd->set_type=set_type; - new_sd->stage_flag=ssb; - - descriptor_map.Add(new_sd->name,new_sd); - - count++; - - return(new_sd); - } -} - const UBODescriptor *MaterialDescriptorInfo::AddUBO(VkShaderStageFlagBits ssb,DescriptorSetType set_type,UBODescriptor *sd) { RANGE_CHECK_RETURN_NULLPTR(set_type); diff --git a/src/ShaderGen/ShaderCreateInfoVertex.cpp b/src/ShaderGen/ShaderCreateInfoVertex.cpp index 66244f42..b1bcd755 100644 --- a/src/ShaderGen/ShaderCreateInfoVertex.cpp +++ b/src/ShaderGen/ShaderCreateInfoVertex.cpp @@ -60,9 +60,4 @@ bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *) return(true); } - -const hgl::graph::ShaderAttributeArray &ShaderCreateInfoVertex::GetInput()const -{ - return spv_data->stage_io.input; -} SHADERGEN_NAMESPACE_END