Skip to content

Commit f810e12

Browse files
committed
xrRender/ResourceManager.cpp: load textures with TBB
1 parent 77cb01c commit f810e12

File tree

1 file changed

+4
-41
lines changed

1 file changed

+4
-41
lines changed

src/Layers/xrRender/ResourceManager.cpp

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <d3dx9.h>
1111
#pragma warning(pop)
1212

13+
#include <tbb/parallel_for_each.h>
14+
1315
#include "ResourceManager.h"
1416
#include "tss.h"
1517
#include "blenders/blender.h"
@@ -341,59 +343,20 @@ void CResourceManager::Delete(const Shader* S)
341343
Msg("! ERROR: Failed to find complete shader");
342344
}
343345

344-
#ifndef USE_OGL
345-
xr_vector<CTexture*> textures_to_load;
346-
347-
void LoadTextures(const size_t thread_num, const size_t textures_per_worker)
348-
{
349-
#ifdef DEBUG
350-
Msg("Thread %d, amount of textures = %d", thread_num, textures_per_worker);
351-
352-
CTimer timer;
353-
timer.Start();
354-
#endif
355-
356-
const auto upperbound = thread_num * textures_per_worker;
357-
const auto lowerbound = upperbound - textures_per_worker;
358-
for (auto i = lowerbound; i < upperbound; i++)
359-
{
360-
if (i < textures_to_load.size())
361-
textures_to_load[i]->Load();
362-
else
363-
break;
364-
}
365-
366-
#ifdef DEBUG
367-
Msg("Thread %d, texture loading time = %d", thread_num, timer.GetElapsed_ms());
368-
#endif
369-
}
370-
#endif
371-
372346
void CResourceManager::DeferredUpload()
373347
{
374348
if (!RDEVICE.b_is_Ready)
375349
return;
376350

377351
#ifndef MASTER_GOLD
378-
Msg("%s, amount of textures = %d", __FUNCTION__ , m_textures.size());
352+
Msg("%s, amount of textures = %d", __FUNCTION__, m_textures.size());
379353

380354
CTimer timer;
381355
timer.Start();
382356
#endif
383357

384358
#ifndef USE_OGL
385-
const auto nWorkers = ttapi.threads.size();
386-
const auto textures_per_worker = m_textures.size() / nWorkers;
387-
388-
for (auto& t : m_textures)
389-
textures_to_load.push_back(t.second);
390-
391-
for (auto i = 1; i <= nWorkers; ++i)
392-
ttapi.threads[i-1]->addJob([=] { LoadTextures(i, textures_per_worker); });
393-
394-
ttapi.wait();
395-
396-
textures_to_load.clear();
359+
tbb::parallel_for_each(m_textures, [&](auto m_tex) { m_tex.second->Load(); });
397360
#else
398361
for (auto& texture : m_textures)
399362
texture.second->Load();

0 commit comments

Comments
 (0)