save codes of UBO in AccumMemoryManager

This commit is contained in:
hyzboy 2024-03-09 20:48:30 +08:00
parent c229259623
commit cdedc81f9f
3 changed files with 36 additions and 12 deletions

2
CMCore

@ -1 +1 @@
Subproject commit f2519a16beb78ee5bb400438988b58cc116fe1a5
Subproject commit 924f4ab9f358d9701fbe9266a18f50903cff1571

View File

@ -1,6 +1,7 @@
#pragma once
#include<hgl/type/Map.h>
#include<hgl/type/StringList.h>
#include<hgl/type/AccumMemoryManager.h>
#include<hgl/graph/VKShaderStage.h>
#include<hgl/graph/VKSamplerType.h>
#include<hgl/graph/VKPrimitiveType.h>
@ -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<UBOData>,会出现问题
// 2.后台将所有UBO文件缓存所以只传递过来一个char *即可
AccumMemoryManager::Block *block;
};
using UBODataList=List<UBOData>;

View File

@ -7,6 +7,9 @@
#include<hgl/io/TextInputStream.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/type/AccumMemoryManager.h>
#include<hgl/io/FileAccess.h>
#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<OSString,AccumMemoryManager::Block *> 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;