|
14 | 14 | #include "tss.h" |
15 | 15 | #include "blenders\blender.h" |
16 | 16 | #include "blenders\blender_recorder.h" |
| 17 | +#include "xrCore/Threading/ThreadPool.hpp" |
17 | 18 |
|
18 | 19 | // Already defined in Texture.cpp |
19 | 20 | void fix_texture_name(LPSTR fn); |
@@ -337,14 +338,44 @@ void CResourceManager::Delete(const Shader* S) |
337 | 338 | Msg("! ERROR: Failed to find complete shader"); |
338 | 339 | } |
339 | 340 |
|
| 341 | +xr_vector<CTexture*> textures_to_load; |
| 342 | + |
| 343 | +void LoadTextures(const size_t thread_num, const size_t textures_per_worker) |
| 344 | +{ |
| 345 | + const auto upperbound = thread_num * textures_per_worker; |
| 346 | + const auto lowerbound = upperbound - textures_per_worker; |
| 347 | + for (auto i = lowerbound; i < upperbound; i++) |
| 348 | + { |
| 349 | + if (i < textures_to_load.size()) |
| 350 | + textures_to_load[i]->Load(); |
| 351 | + else |
| 352 | + break; |
| 353 | + } |
| 354 | +} |
| 355 | + |
340 | 356 | void CResourceManager::DeferredUpload() |
341 | 357 | { |
342 | 358 | if (!RDEVICE.b_is_Ready) |
343 | 359 | return; |
344 | | - for (auto t = m_textures.begin(); t != m_textures.end(); t++) |
345 | | - { |
346 | | - t->second->Load(); |
347 | | - } |
| 360 | + |
| 361 | + Msg("%s, amount of textures = %d", __FUNCTION__ , m_textures.size()); |
| 362 | + |
| 363 | + CTimer timer; |
| 364 | + timer.Start(); |
| 365 | + |
| 366 | + const auto nWorkers = ttapi.threads.size(); |
| 367 | + const auto textures_per_worker = m_textures.size() / nWorkers; |
| 368 | + |
| 369 | + for (auto& t : m_textures) |
| 370 | + textures_to_load.push_back(t.second); |
| 371 | + |
| 372 | + for (auto i = 1; i < nWorkers; ++i) |
| 373 | + ttapi.threads[i]->addJob([=] { LoadTextures(i, textures_per_worker); }); |
| 374 | + |
| 375 | + ttapi.wait(); |
| 376 | + |
| 377 | + textures_to_load.clear(); |
| 378 | + Msg("%s, texture loading time = %d", __FUNCTION__, timer.GetElapsed_ms()); |
348 | 379 | } |
349 | 380 | /* |
350 | 381 | void CResourceManager::DeferredUnload () |
|
0 commit comments