diff --git a/CMCore b/CMCore index f2519a16..924f4ab9 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit f2519a16beb78ee5bb400438988b58cc116fe1a5 +Subproject commit 924f4ab9f358d9701fbe9266a18f50903cff1571 diff --git a/src/ShaderGen/MaterialFileData.h b/src/ShaderGen/MaterialFileData.h index 79b22501..cbc943a2 100644 --- a/src/ShaderGen/MaterialFileData.h +++ b/src/ShaderGen/MaterialFileData.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include #include @@ -42,12 +43,7 @@ namespace material_file uint32_t shader_stage_flag_bits; - const char *codes; - uint code_length; - - //为什么不使用AnsiString保存ubo shader codes ? - // 1.MaterialFileData中使用UBODataList也就是List,会出现问题 - // 2.后台将所有UBO文件缓存,所以只传递过来一个char *即可 + AccumMemoryManager::Block *block; }; using UBODataList=List; diff --git a/src/ShaderGen/MaterialFileLoader.cpp b/src/ShaderGen/MaterialFileLoader.cpp index ea63cc8c..a81ebd03 100644 --- a/src/ShaderGen/MaterialFileLoader.cpp +++ b/src/ShaderGen/MaterialFileLoader.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #include"MaterialFileData.h" STD_MTL_NAMESPACE_BEGIN @@ -630,6 +633,35 @@ namespace namespace { constexpr const os_char HGL_SHADER_LIBRARY_FOLDER[]=OS_TEXT("ShaderLibrary"); + + AccumMemoryManager ubo_memory; + hgl::Map ubo_codes_map; + + AccumMemoryManager::Block *GetUBOCodes(const OSString &filename) + { + AccumMemoryManager::Block *block; + + if(ubo_codes_map.Get(filename,block)) + return block; + + hgl::io::FileAccess fa; + + if(!fa.OpenRead(filename)) + { + ubo_codes_map.Add(filename,nullptr); + return(nullptr); + } + + const int64 size=fa.GetSize(); + + block=ubo_memory.Acquire(size); + + fa.Read(ubo_memory.Access(block),size); + + ubo_codes_map.Add(filename,block); + + return block; + } }//namespace MaterialFileData *LoadMaterialDataFromFile(const AnsiString &mtl_filename) @@ -673,11 +705,7 @@ MaterialFileData *LoadMaterialDataFromFile(const AnsiString &mtl_filename) else ubo_os_full_filename=filesystem::MergeFilename(mtl_path,ubo_os_fn); - if(!filesystem::FileExist(ubo_os_full_filename)) - continue; - - char *data; - int size=filesystem::LoadFileToMemory(ubo_os_full_filename,(void **)&data,true); + ud.block=GetUBOCodes(ubo_os_full_filename); } return mfd;