Skip to content

Commit

Permalink
Multithreading: use tbb::parallel_for to calculate RASTER-triangles
Browse files Browse the repository at this point in the history
Changed prefetch log
  • Loading branch information
Xottab-DUTY committed May 14, 2018
1 parent e63fb12 commit 07d57d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 37 deletions.
42 changes: 25 additions & 17 deletions src/Layers/xrRender/HOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>

#include "HOM.h"
#include "occRasterizer.h"
#include "xrEngine/GameFont.h"
Expand Down Expand Up @@ -93,26 +97,30 @@ void CHOM::Load()

// Create RASTER-triangles
m_pTris = xr_alloc<occTri>(u32(CL.getTS()));
for (u32 it = 0; it < CL.getTS(); it++)

tbb::parallel_for(tbb::blocked_range<u32>(0, CL.getTS()), [&](const auto& range)
{
CDB::TRI& clT = CL.getT()[it];
occTri& rT = m_pTris[it];
Fvector& v0 = CL.getV()[clT.verts[0]];
Fvector& v1 = CL.getV()[clT.verts[1]];
Fvector& v2 = CL.getV()[clT.verts[2]];
rT.adjacent[0] = (0xffffffff == adjacency[3 * it + 0]) ? ((occTri*)(-1)) : (m_pTris + adjacency[3 * it + 0]);
rT.adjacent[1] = (0xffffffff == adjacency[3 * it + 1]) ? ((occTri*)(-1)) : (m_pTris + adjacency[3 * it + 1]);
rT.adjacent[2] = (0xffffffff == adjacency[3 * it + 2]) ? ((occTri*)(-1)) : (m_pTris + adjacency[3 * it + 2]);
rT.flags = clT.dummy;
rT.area = Area(v0, v1, v2);
if (rT.area < EPS_L)
for (u32 it = range.begin(); it != range.end(); ++it)
{
Msg("! Invalid HOM triangle (%f,%f,%f)-(%f,%f,%f)-(%f,%f,%f)", VPUSH(v0), VPUSH(v1), VPUSH(v2));
CDB::TRI& clT = CL.getT()[it];
occTri& rT = m_pTris[it];
Fvector& v0 = CL.getV()[clT.verts[0]];
Fvector& v1 = CL.getV()[clT.verts[1]];
Fvector& v2 = CL.getV()[clT.verts[2]];
rT.adjacent[0] = (0xffffffff == adjacency[3 * it + 0]) ? ((occTri*)(-1)) : (m_pTris + adjacency[3 * it + 0]);
rT.adjacent[1] = (0xffffffff == adjacency[3 * it + 1]) ? ((occTri*)(-1)) : (m_pTris + adjacency[3 * it + 1]);
rT.adjacent[2] = (0xffffffff == adjacency[3 * it + 2]) ? ((occTri*)(-1)) : (m_pTris + adjacency[3 * it + 2]);
rT.flags = clT.dummy;
rT.area = Area(v0, v1, v2);

if (rT.area < EPS_L)
Msg("! Invalid HOM triangle (%f,%f,%f)-(%f,%f,%f)-(%f,%f,%f)", VPUSH(v0), VPUSH(v1), VPUSH(v2));

rT.plane.build(v0, v1, v2);
rT.skip = 0;
rT.center.add(v0, v1).add(v2).div(3.f);
}
rT.plane.build(v0, v1, v2);
rT.skip = 0;
rT.center.add(v0, v1).add(v2).div(3.f);
}
});

// Create AABB-tree
m_pModel = new CDB::MODEL();
Expand Down
3 changes: 1 addition & 2 deletions src/Layers/xrRender/ModelPool.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "stdafx.h"
#pragma hdrstop

#include "ModelPool.h"

Expand Down Expand Up @@ -395,7 +394,7 @@ void CModelPool::Prefetch()
// prefetch visuals
string256 section;
strconcat(sizeof(section), section, "prefetch_visuals_", g_pGamePersistent->m_game_params.m_game_type);
CInifile::Sect& sect = pSettings->r_section(section);
const CInifile::Sect& sect = pSettings->r_section(section);
for (auto I = sect.Data.cbegin(); I != sect.Data.cend(); I++)
{
const CInifile::Item& item = *I;
Expand Down
11 changes: 0 additions & 11 deletions src/Layers/xrRender/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,12 @@ void CResourceManager::DeferredUpload()
if (!RDEVICE.b_is_Ready)
return;

#ifndef MASTER_GOLD
Msg("%s, amount of textures: %d", __FUNCTION__, m_textures.size());

CTimer timer;
timer.Start();
#endif

#ifndef USE_OGL
tbb::parallel_for_each(m_textures, [&](auto m_tex) { m_tex.second->Load(); });
#else
for (auto& texture : m_textures)
texture.second->Load();
#endif

#ifndef MASTER_GOLD
Msg("%s, texture loading time: %d ms", __FUNCTION__, timer.GetElapsed_ms());
#endif
}
/*
void CResourceManager::DeferredUnload ()
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/ResourceManager_Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma hdrstop

#include "ResourceManager.h"
#include "blenders\blender.h"
#include "blenders/blender.h"

void CResourceManager::OnDeviceDestroy(BOOL)
{
Expand Down
14 changes: 8 additions & 6 deletions src/xrEngine/IGame_Persistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,23 @@ void IGame_Persistent::OnGameStart()
void IGame_Persistent::Prefetch()
{
// prefetch game objects & models
float p_time = 1000.f * Device.GetTimerGlobal()->GetElapsed_sec();
u32 mem_0 = Memory.mem_usage();
CTimer timer;
timer.Start();
const auto memoryBefore = Memory.mem_usage();

Log("Loading objects...");
ObjectPool.prefetch();

Log("Loading models...");
GEnv.Render->models_Prefetch();

Log("Loading textures...");
GEnv.Render->ResourcesDeferredUpload();

p_time = 1000.f * Device.GetTimerGlobal()->GetElapsed_sec() - p_time;
u32 p_mem = Memory.mem_usage() - mem_0;
const auto memoryAfter = Memory.mem_usage() - memoryBefore;

Msg("* [prefetch] time: %d ms", iFloor(p_time));
Msg("* [prefetch] memory: %dKb", p_mem / 1024);
Msg("* [prefetch] time: %d ms", timer.GetElapsed_ms());
Msg("* [prefetch] memory: %d Kb", memoryAfter / 1024);
}
#endif

Expand Down

0 comments on commit 07d57d7

Please sign in to comment.