Skip to content

Commit

Permalink
Replace FixedMap with xr_vector. Delete FixedMAP. Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Feb 2, 2018
1 parent 8e9fe15 commit 3b46e4a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 432 deletions.
10 changes: 5 additions & 5 deletions src/Layers/xrRender/D3DXRenderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ class D3DXRenderBase : public IRender, public pureFrame
mapMatrixPasses[0][i].clear();
mapMatrixPasses[1][i].clear();
}
mapSorted.destroy();
mapHUD.destroy();
mapSorted.clear();
mapHUD.clear();
mapLOD.clear();
mapDistort.destroy();
mapDistort.clear();

#if RENDER != R_R1
mapWmark.destroy();
mapEmissive.destroy();
mapWmark.clear();
mapEmissive.clear();
#endif
}

Expand Down
108 changes: 26 additions & 82 deletions src/Layers/xrRender/r__dsgraph_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
// a) Allow to optimize RT order
// b) Should be rendered to special distort buffer in another pass
VERIFY(pVisual->shader._get());
ShaderElement* sh_d = &*pVisual->shader->E[4];
ShaderElement* sh_d = &*pVisual->shader->E[4]; // 4=L_special
if (RImplementation.o.distortion && sh_d && sh_d->flags.bDistort && pmask[sh_d->flags.iPriority / 2])
{
mapSorted_Node* N = mapDistort.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = RI.val_pObject;
N->val.pVisual = pVisual;
N->val.Matrix = *RI.val_pTransform;
N->val.se = sh_d; // 4=L_special
mapDistort.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
}

// Select shader
Expand All @@ -75,62 +70,35 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
if (!pmask[sh->flags.iPriority / 2])
return;

// Create common node
// NOTE: Invisible elements exist only in R1
_MatrixItem item = {SSA, RI.val_pObject, pVisual, *RI.val_pTransform};

// HUD rendering
if (RI.val_bHUD)
{
if (sh->flags.bStrictB2F)
{
mapSorted_Node* N = mapSorted.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = RI.val_pObject;
N->val.pVisual = pVisual;
N->val.Matrix = *RI.val_pTransform;
N->val.se = sh;
return;
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
}
else
{
mapHUD_Node* N = mapHUD.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = RI.val_pObject;
N->val.pVisual = pVisual;
N->val.Matrix = *RI.val_pTransform;
N->val.se = sh;
mapHUD.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
#if RENDER != R_R1
if (sh->flags.bEmissive)
{
mapSorted_Node* N2 = mapHUDEmissive.insertInAnyWay(distSQ);
N2->val.ssa = SSA;
N2->val.pObject = RI.val_pObject;
N2->val.pVisual = pVisual;
N2->val.Matrix = *RI.val_pTransform;
N2->val.se = &*pVisual->shader->E[4]; // 4=L_special
}
#endif // RENDER!=R_R1
return;
mapHUDEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
#endif // RENDER!=R_R1
}
return;
}

// Shadows registering
#if RENDER == R_R1
RI.L_Shadows->add_element(item);
RI.L_Shadows->add_element(_MatrixItem{ SSA, RI.val_pObject, pVisual, *RI.val_pTransform });
#endif
if (RI.val_bInvisible)
return;

// strict-sorting selection
if (sh->flags.bStrictB2F)
{
mapSorted_Node* N = mapSorted.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = RI.val_pObject;
N->val.pVisual = pVisual;
N->val.Matrix = *RI.val_pTransform;
N->val.se = sh;
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
return;
}

Expand All @@ -142,25 +110,19 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
// d) Should be rendered to accumulation buffer in the second pass
if (sh->flags.bEmissive)
{
mapSorted_Node* N = mapEmissive.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = RI.val_pObject;
N->val.pVisual = pVisual;
N->val.Matrix = *RI.val_pTransform;
N->val.se = &*pVisual->shader->E[4]; // 4=L_special
mapEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
}
if (sh->flags.bWmark && pmask_wmark)
{
mapSorted_Node* N = mapWmark.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = RI.val_pObject;
N->val.pVisual = pVisual;
N->val.Matrix = *RI.val_pTransform;
N->val.se = sh;
mapWmark.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
return;
}
#endif

// Create common node
// NOTE: Invisible elements exist only in R1
_MatrixItem item = { SSA, RI.val_pObject, pVisual, *RI.val_pTransform };

for (u32 iPass = 0; iPass < sh->passes.size(); ++iPass)
{
auto &pass = *sh->passes[iPass];
Expand Down Expand Up @@ -262,15 +224,10 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
// a) Allow to optimize RT order
// b) Should be rendered to special distort buffer in another pass
VERIFY(pVisual->shader._get());
ShaderElement* sh_d = &*pVisual->shader->E[4];
ShaderElement* sh_d = &*pVisual->shader->E[4]; // 4=L_special
if (RImplementation.o.distortion && sh_d && sh_d->flags.bDistort && pmask[sh_d->flags.iPriority / 2])
{
mapSorted_Node* N = mapDistort.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = nullptr;
N->val.pVisual = pVisual;
N->val.Matrix = Fidentity;
N->val.se = &*pVisual->shader->E[4]; // 4=L_special
mapDistort.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, nullptr, pVisual, Fidentity, sh_d }))); // sh_d -> L_special
}

// Select shader
Expand All @@ -283,11 +240,9 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
// strict-sorting selection
if (sh->flags.bStrictB2F)
{
mapSorted_Node* N = mapSorted.insertInAnyWay(distSQ);
N->val.pObject = nullptr;
N->val.pVisual = pVisual;
N->val.Matrix = Fidentity;
N->val.se = sh;
// TODO: Выяснить, почему в единственном месте параметр ssa не используется
// Визуально различий не замечено
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ /*0*/SSA, nullptr, pVisual, Fidentity, sh })));
return;
}

Expand All @@ -299,21 +254,11 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
// d) Should be rendered to accumulation buffer in the second pass
if (sh->flags.bEmissive)
{
mapSorted_Node* N = mapEmissive.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = NULL;
N->val.pVisual = pVisual;
N->val.Matrix = Fidentity;
N->val.se = &*pVisual->shader->E[4]; // 4=L_special
mapEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, nullptr, pVisual, Fidentity, sh_d }))); // sh_d -> L_special
}
if (sh->flags.bWmark && pmask_wmark)
{
mapSorted_Node* N = mapWmark.insertInAnyWay(distSQ);
N->val.ssa = SSA;
N->val.pObject = NULL;
N->val.pVisual = pVisual;
N->val.Matrix = Fidentity;
N->val.se = sh;
mapWmark.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, nullptr, pVisual, Fidentity, sh })));
return;
}
#endif
Expand All @@ -323,14 +268,14 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)

counter_S++;

_NormalItem item = {SSA, pVisual};
_NormalItem item = { SSA, pVisual };

for (u32 iPass = 0; iPass < sh->passes.size(); ++iPass)
{
auto &pass = *sh->passes[iPass];
auto &map = mapNormalPasses[sh->flags.iPriority / 2][iPass];

#if defined(USE_OGL)
#ifdef USE_OGL
auto &Nvs = map[pass.vs->vs];
auto &Ngs = Nvs[pass.gs->gs];
auto &Nps = Ngs[pass.ps->ps];
Expand All @@ -351,7 +296,6 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
#else
auto &Ncs = Nps[pass.constants._get()];
#endif
//auto &Nstate = Ncs[pass.state->state];
auto &Nstate = Ncs[&*pass.state];
auto &Ntex = Nstate[pass.T._get()];
Ntex.push_back(item);
Expand All @@ -375,7 +319,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
{
Nps.ssa = SSA;
#endif
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
if (SSA > Ngs.ssa)
{
Ngs.ssa = SSA;
Expand All @@ -384,7 +328,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
{
Nvs.ssa = SSA;
}
#if defined(USE_DX10) || defined(USE_DX11)
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
}
#endif
}
Expand Down
44 changes: 27 additions & 17 deletions src/Layers/xrRender/r__dsgraph_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ ICF float calcLOD(float ssa /*fDistSq*/, float /*R*/)
}

// ALPHA
void __fastcall sorted_L1(mapSorted_Node* N)
void __fastcall sorted_L1(mapSorted_T::value_type &N)
{
VERIFY(N);
dxRender_Visual* V = N->val.pVisual;
dxRender_Visual* V = N.second.pVisual;
VERIFY(V && V->shader._get());
RCache.set_Element(N->val.se);
RCache.set_xform_world(N->val.Matrix);
RImplementation.apply_object(N->val.pObject);
RCache.set_Element(N.second.se);
RCache.set_xform_world(N.second.Matrix);
RImplementation.apply_object(N.second.pObject);
RImplementation.apply_lmaterial();
V->Render(calcLOD(N->key, V->vis.sphere.R));
V->Render(calcLOD(N.first, V->vis.sphere.R));
}

template <class T> IC bool cmp_second_ssa(const T &lhs, const T &rhs) { return (lhs->second.ssa > rhs->second.ssa); }
Expand Down Expand Up @@ -343,6 +343,9 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
BasicStats.Primitives.End();
}


template <class T> IC bool cmp_first_l(const T &lhs, const T &rhs) { return (lhs.first < rhs.first); }
template <class T> IC bool cmp_first_h(const T &lhs, const T &rhs) { return (lhs.first > rhs.first); }
//////////////////////////////////////////////////////////////////////////
// HUD render
void D3DXRenderBase::r_dsgraph_render_hud()
Expand All @@ -362,7 +365,9 @@ void D3DXRenderBase::r_dsgraph_render_hud()

// Rendering
rmNear();
mapHUD.traverseLR(sorted_L1);
std::sort(mapHUD.begin(), mapHUD.end(), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
for (auto &i : mapHUD)
sorted_L1(i);
mapHUD.clear();

#if RENDER == R_R1
Expand Down Expand Up @@ -468,8 +473,9 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
// strict-sorted render
void D3DXRenderBase::r_dsgraph_render_sorted()
{
// Sorted (back to front)
mapSorted.traverseRL(sorted_L1);
std::sort(mapSorted.begin(), mapSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
for (auto &i : mapSorted)
sorted_L1(i);
mapSorted.clear();
}

Expand All @@ -478,8 +484,9 @@ void D3DXRenderBase::r_dsgraph_render_sorted()
void D3DXRenderBase::r_dsgraph_render_emissive()
{
#if RENDER != R_R1
// Sorted (back to front)
mapEmissive.traverseLR(sorted_L1);
std::sort(mapEmissive.begin(), mapEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
for (auto &i : mapEmissive)
sorted_L1(i);
mapEmissive.clear();

// HACK: Calculate this only once
Expand All @@ -497,8 +504,9 @@ void D3DXRenderBase::r_dsgraph_render_emissive()

// Rendering
rmNear();
// Sorted (back to front)
mapHUDEmissive.traverseLR(sorted_L1);
std::sort(mapHUDEmissive.begin(), mapHUDEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
for (auto &i : mapHUDEmissive)
sorted_L1(i);
mapHUDEmissive.clear();

rmNormal();
Expand All @@ -515,8 +523,9 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
void D3DXRenderBase::r_dsgraph_render_wmarks()
{
#if RENDER != R_R1
// Sorted (back to front)
mapWmark.traverseLR(sorted_L1);
std::sort(mapWmark.begin(), mapWmark.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
for (auto &i : mapWmark)
sorted_L1(i);
mapWmark.clear();
#endif
}
Expand All @@ -525,8 +534,9 @@ void D3DXRenderBase::r_dsgraph_render_wmarks()
// strict-sorted render
void D3DXRenderBase::r_dsgraph_render_distort()
{
// Sorted (back to front)
mapDistort.traverseRL(sorted_L1);
std::sort(mapDistort.begin(), mapDistort.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
for (auto &i : mapDistort)
sorted_L1(i);
mapDistort.clear();
}

Expand Down
22 changes: 12 additions & 10 deletions src/Layers/xrRender/r__dsgraph_types.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "xrCore/FixedMap.h"

class dxRender_Visual;

namespace R_dsgraph
Expand All @@ -21,8 +19,16 @@ struct _MatrixItem
Fmatrix Matrix; // matrix (copy)
};

struct _MatrixItemS : public _MatrixItem
struct _MatrixItemS
{
// Хак для использования списков инициализации
// Не используем наследование
// _MatrixItem begin
float ssa;
IRenderable* pObject;
dxRender_Visual* pVisual;
Fmatrix Matrix; // matrix (copy)
// _MatrixItem end
ShaderElement* se;
};

Expand Down Expand Up @@ -164,11 +170,7 @@ using mapMatrix_T = mapMatrixVS;
using mapMatrixPasses_T = mapMatrix_T[SHADER_PASSES_MAX];

// Top level
using mapSorted_T = FixedMAP<float, _MatrixItemS>;
using mapSorted_Node = mapSorted_T::TNode;

using mapHUD_T = FixedMAP<float, _MatrixItemS>;
using mapHUD_Node = mapHUD_T::TNode;

using mapLOD_T = xr_vector<std::pair<float, _LodItem>>;
using mapSorted_T = xr_vector<std::pair<float, _MatrixItemS>>;
using mapHUD_T = xr_vector<std::pair<float, _MatrixItemS>>;
using mapLOD_T = xr_vector<std::pair<float, _LodItem>>;
}
Loading

0 comments on commit 3b46e4a

Please sign in to comment.