mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
If hash match reuse existing shaders instead creating.
This commit is contained in:
16
src/bgfx_p.h
16
src/bgfx_p.h
@@ -3056,11 +3056,23 @@ namespace bgfx
|
||||
return invalid;
|
||||
}
|
||||
|
||||
uint32_t shaderHash = bx::hashMurmur2A(_mem->data, _mem->size);
|
||||
uint16_t idx = m_shaderHashMap.find(shaderHash);
|
||||
if (kInvalidHandle != idx)
|
||||
{
|
||||
ShaderHandle handle = { idx };
|
||||
shaderIncRef(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
ShaderHandle handle = { m_shaderHandle.alloc() };
|
||||
|
||||
BX_WARN(isValid(handle), "Failed to allocate shader handle.");
|
||||
if (isValid(handle) )
|
||||
{
|
||||
bool ok = m_shaderHashMap.insert(shaderHash, handle.idx);
|
||||
BX_CHECK(ok, "Shader already exists!"); BX_UNUSED(ok);
|
||||
|
||||
uint32_t iohash;
|
||||
bx::read(&reader, iohash);
|
||||
|
||||
@@ -3194,6 +3206,8 @@ namespace bgfx
|
||||
sr.m_uniforms = NULL;
|
||||
sr.m_num = 0;
|
||||
}
|
||||
|
||||
m_shaderHashMap.removeByHandle(_handle.idx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4373,6 +4387,8 @@ namespace bgfx
|
||||
UniformHashMap m_uniformHashMap;
|
||||
UniformRef m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS];
|
||||
|
||||
typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_SHADERS*2> ShaderHashMap;
|
||||
ShaderHashMap m_shaderHashMap;
|
||||
ShaderRef m_shaderRef[BGFX_CONFIG_MAX_SHADERS];
|
||||
|
||||
typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_PROGRAMS*2> ProgramHashMap;
|
||||
|
||||
Reference in New Issue
Block a user