Skip to content

Commit

Permalink
Part 4 of the experiment to remove doug_lea_allocator.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr authored and Xottab-DUTY committed Dec 24, 2017
1 parent 7ceaaf0 commit 7fa1862
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 87 deletions.
36 changes: 36 additions & 0 deletions src/Layers/xrRender/D3DXRenderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,31 @@ class D3DXRenderBase : public IRender, public pureFrame
R_dsgraph::mapSorted_T mapHUDEmissive;
#endif

// Runtime structures
xr_vector<R_dsgraph::mapNormalVS::TNode*> nrmVS;
#if defined(USE_DX10) || defined(USE_DX11)
xr_vector<R_dsgraph::mapNormalGS::TNode*> nrmGS;
#endif // USE_DX10
xr_vector<R_dsgraph::mapNormalPS::TNode*> nrmPS;
xr_vector<R_dsgraph::mapNormalCS::TNode*> nrmCS;
xr_vector<R_dsgraph::mapNormalStates::TNode*> nrmStates;
xr_vector<R_dsgraph::mapNormalTextures::TNode*> nrmTextures;
xr_vector<R_dsgraph::mapNormalTextures::TNode*> nrmTexturesTemp;

xr_vector<R_dsgraph::mapMatrixVS::TNode*> matVS;
#if defined(USE_DX10) || defined(USE_DX11)
xr_vector<R_dsgraph::mapMatrixGS::TNode*> matGS;
#endif // USE_DX10
xr_vector<R_dsgraph::mapMatrixPS::TNode*> matPS;
xr_vector<R_dsgraph::mapMatrixCS::TNode*> matCS;
xr_vector<R_dsgraph::mapMatrixStates::TNode*> matStates;
xr_vector<R_dsgraph::mapMatrixTextures::TNode*> matTextures;
xr_vector<R_dsgraph::mapMatrixTextures::TNode*> matTexturesTemp;
xr_vector<R_dsgraph::_LodItem> lstLODs;
xr_vector<int> lstLODgroups;
xr_vector<ISpatial*> lstRenderables;
xr_vector<ISpatial*> lstSpatial;
xr_vector<dxRender_Visual*> lstVisuals;

u32 counter_S;
u32 counter_D;
Expand Down Expand Up @@ -92,10 +113,25 @@ class D3DXRenderBase : public IRender, public pureFrame

void r_dsgraph_destroy()
{
nrmVS.clear();
nrmPS.clear();
nrmCS.clear();
nrmStates.clear();
nrmTextures.clear();
nrmTexturesTemp.clear();

matVS.clear();
matPS.clear();
matCS.clear();
matStates.clear();
matTextures.clear();
matTexturesTemp.clear();

lstLODs.clear();
lstLODgroups.clear();
lstRenderables.clear();
lstSpatial.clear();
lstVisuals.clear();

for (int i = 0; i < SHADER_PASSES_MAX; ++i)
{
Expand Down
52 changes: 34 additions & 18 deletions src/Layers/xrRender/r__dsgraph_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ template <class T> IC bool cmp_textures_lexN(const T &lhs, const T &rhs)
return std::lexicographical_compare(t1->begin(), t1->end(), t2->begin(), t2->end());
}

template <class T> void sort_tlist(xr_vector<T::template TNode*>& lst, T& textures)
template <class T> void sort_tlist(xr_vector<T::template TNode*>& lst, xr_vector<T::template TNode*>& temp, T& textures)
{
int amount = textures.begin()->key->size();

Expand All @@ -82,8 +82,6 @@ template <class T> void sort_tlist(xr_vector<T::template TNode*>& lst, T& textur
}
else
{
xr_vector<T::template TNode*> temp;

// Split into 2 parts
for (auto &it : textures)
{
Expand Down Expand Up @@ -123,7 +121,6 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
{
mapNormalVS& vs = mapNormalPasses[_priority][iPass];

xr_vector<mapNormalVS::TNode*> nrmVS;
vs.getANY_P(nrmVS);
std::sort(nrmVS.begin(), nrmVS.end(), cmp_val_ssa<mapNormalVS::TNode*>);
for (auto & vs_it : nrmVS)
Expand All @@ -133,8 +130,8 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
#if defined(USE_DX10) || defined(USE_DX11)
// GS setup
mapNormalGS& gs = vs_it->val;
gs.ssa = 0;

xr_vector<mapNormalGS::TNode*> nrmGS;
gs.getANY_P(nrmGS);
std::sort(nrmGS.begin(), nrmGS.end(), cmp_val_ssa<mapNormalGS::TNode*>);
for (auto & gs_it : nrmGS)
Expand All @@ -145,7 +142,8 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
#else // USE_DX10
mapNormalPS& ps = vs_it->val;
#endif // USE_DX10
xr_vector<mapNormalPS::TNode*> nrmPS;
ps.ssa = 0;

ps.getANY_P(nrmPS);
std::sort(nrmPS.begin(), nrmPS.end(), cmp_ps_val_ssa<mapNormalPS::TNode*>);
for (auto &ps_it : nrmPS)
Expand All @@ -159,32 +157,34 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
#else
mapNormalCS& cs = ps_it->val;
#endif
xr_vector<mapNormalCS::TNode*> nrmCS;
cs.ssa = 0;

cs.getANY_P(nrmCS);
std::sort(nrmCS.begin(), nrmCS.end(), cmp_val_ssa<mapNormalCS::TNode*>);
for (auto &cs_it : nrmCS)
{
RCache.set_Constants(cs_it->key);

mapNormalStates& states = cs_it->val;
states.ssa = 0;

xr_vector<mapNormalStates::TNode*> nrmStates;
states.getANY_P(nrmStates);
std::sort(nrmStates.begin(), nrmStates.end(), cmp_val_ssa<mapNormalStates::TNode*>);
for (auto &state_it : nrmStates)
{
RCache.set_States(state_it->key);

mapNormalTextures& tex = state_it->val;
tex.ssa = 0;

xr_vector<mapNormalTextures::TNode*> nrmTextures;
sort_tlist<mapNormalTextures>(nrmTextures, tex);
sort_tlist<mapNormalTextures>(nrmTextures, nrmTexturesTemp, tex);
for (auto &tex_it : nrmTextures)
{
RCache.set_Textures(tex_it->key);
RImplementation.apply_lmaterial();

mapNormalItems& items = tex_it->val;
items.ssa = 0;

std::sort(items.begin(), items.end(), cmp_ssa<_NormalItem>);
for (auto &it_it : items)
Expand All @@ -197,18 +197,25 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
}
items.clear();
}
nrmTexturesTemp.clear();
nrmTextures.clear();
tex.clear();
}
nrmStates.clear();
states.clear();
}
nrmCS.clear();
cs.clear();
}
nrmPS.clear();
ps.clear();
#if defined(USE_DX10) || defined(USE_DX11)
}
nrmGS.clear();
gs.clear();
#endif // USE_DX10
}
nrmVS.clear();
vs.clear();
}
}
Expand All @@ -221,7 +228,6 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
{
mapMatrixVS& vs = mapMatrixPasses[_priority][iPass];

xr_vector<mapMatrixVS::TNode*> matVS;
vs.getANY_P(matVS);
std::sort(matVS.begin(), matVS.end(), cmp_val_ssa<mapMatrixVS::TNode*>);
for (auto &vs_id : matVS)
Expand All @@ -230,8 +236,8 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)

#if defined(USE_DX10) || defined(USE_DX11)
mapMatrixGS& gs = vs_id->val;
gs.ssa = 0;

xr_vector<mapMatrixGS::TNode*> matGS;
gs.getANY_P(matGS);
std::sort(matGS.begin(), matGS.end(), cmp_val_ssa<mapMatrixGS::TNode*>);
for (auto &gs_it : matGS)
Expand All @@ -242,7 +248,8 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
#else // USE_DX10
mapMatrixPS& ps = vs_id->val;
#endif // USE_DX10
xr_vector<mapMatrixPS::TNode *> matPS;
ps.ssa = 0;

ps.getANY_P(matPS);
std::sort(matPS.begin(), matPS.end(), cmp_ps_val_ssa<mapMatrixPS::TNode *>);
for (auto &ps_it : matPS)
Expand All @@ -256,32 +263,34 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
#else
mapMatrixCS& cs = ps_it->val;
#endif
xr_vector<mapMatrixCS::TNode*> matCS;
cs.ssa = 0;

cs.getANY_P(matCS);
std::sort(matCS.begin(), matCS.end(), cmp_val_ssa<mapMatrixCS::TNode*>);
for (auto &cs_it : matCS)
{
RCache.set_Constants(cs_it->key);

mapMatrixStates& states = cs_it->val;
states.ssa = 0;

xr_vector<mapMatrixStates::TNode*> matStates;
states.getANY_P(matStates);
std::sort(matStates.begin(), matStates.end(), cmp_val_ssa<mapMatrixStates::TNode*>);
for (auto &state_it : matStates)
{
RCache.set_States(state_it->key);

mapMatrixTextures& tex = state_it->val;
tex.ssa = 0;

xr_vector<mapMatrixTextures::TNode*> matTextures;
sort_tlist<mapMatrixTextures>(matTextures, tex);
sort_tlist<mapMatrixTextures>(matTextures, matTexturesTemp, tex);
for (auto &tex_it : matTextures)
{
RCache.set_Textures(tex_it->key);
RImplementation.apply_lmaterial();

mapMatrixItems& items = tex_it->val;
items.ssa = 0;

std::sort(items.begin(), items.end(), cmp_ssa<_MatrixItem>);
for (auto &ni_it : items)
Expand All @@ -298,18 +307,25 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
}
items.clear();
}
matTexturesTemp.clear();
matTextures.clear();
tex.clear();
}
matStates.clear();
states.clear();
}
matCS.clear();
cs.clear();
}
matPS.clear();
ps.clear();
#if defined(USE_DX10) || defined(USE_DX11)
}
matGS.clear();
gs.clear();
#endif // USE_DX10
}
matVS.clear();
vs.clear();
}

Expand Down Expand Up @@ -603,7 +619,7 @@ void D3DXRenderBase::r_dsgraph_render_subspace(IRender_Sector* _sector, CFrustum

void D3DXRenderBase::r_dsgraph_render_R1_box(IRender_Sector* S, Fbox& BB, int sh)
{
xr_vector<dxRender_Visual*> lstVisuals;
lstVisuals.clear();
lstVisuals.push_back(((CSector*)S)->root());

for (auto &it : lstVisuals)
Expand Down
74 changes: 7 additions & 67 deletions src/xrCommon/xr_vector.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#pragma once
#include <vector>
#include "xrCore/Memory/xalloc.h"
#include "xrCore/xrDebug_macros.h"

#ifdef _M_AMD64
#define M_DONTDEFERCLEAR_EXT
#endif

#define M_DONTDEFERCLEAR_EXT // for mem-debug only

#define DEF_VECTOR(N, T)\
typedef xr_vector<T> N;\
Expand All @@ -17,6 +10,9 @@
typedef xr_vector<T> N;\
typedef N::iterator I;

//template <typename T, typename allocator = xalloc<T>>
//using xr_vector = class std::vector<T, allocator>;

// vector
template <typename T, typename allocator = xalloc<T>>
class xr_vector : public std::vector<T, allocator>
Expand All @@ -27,65 +23,9 @@ class xr_vector : public std::vector<T, allocator>
using allocator_type = allocator;

xr_vector() : inherited() {}
xr_vector(size_t _count) : inherited(_count) {}
xr_vector(size_t _count, const T& _value) : inherited(_count, _value) {}
explicit xr_vector(size_t _count) : inherited(_count) {}
u32 size() const throw() { return (u32)inherited::size(); }

void clear_and_free() throw() { inherited::clear(); }
void clear_not_free() { erase(begin(), end()); }
void clear_and_reserve()
{
if (capacity() <= size() + size()/4)
clear_not_free();
else
{
u32 old = size();
clear_and_free();
reserve(old);
}
}
#ifdef M_DONTDEFERCLEAR_EXT // defined (or not) by xalloc.h
void clear() { clear_and_free(); }
#else
void clear() { clear_not_free(); }
#endif
const_reference operator[](size_type _Pos) const
{
check_idx(_Pos);
return *(begin()+_Pos);
}
reference operator[](size_type _Pos)
{
check_idx(_Pos);
return *(begin()+_Pos);
}

private:
void check_idx(size_type _Pos) const
{
VERIFY2(_Pos < size(),
make_string("index is out of range: index requested[%d], size of container[%d]",
_Pos, size()).c_str());
}
};

// vector<bool>
template <>
class xr_vector<bool, xalloc<bool>> : public std::vector<bool, xalloc<bool>>
{
using inherited = std::vector<bool, xalloc<bool>>;

public:
u32 size() const { return (u32)inherited::size(); }
void clear() { erase(begin(), end()); }
};

template <typename allocator>
class xr_vector<bool, allocator> : public std::vector<bool, allocator>
{
using inherited = std::vector<bool, allocator>;

public:
u32 size() const { return (u32)inherited::size(); }
void clear() { erase(begin(), end()); }
IC void clear_and_free() { clear(); }
IC void clear_not_free() { clear(); }
IC void clear_and_reserve() { clear(); }
};
4 changes: 2 additions & 2 deletions src/xrCore/FixedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class FixedMAP
{
if (nodes)
{
for (TNode* cur = begin(); cur != end(); cur++)
for (TNode* cur = begin(); cur != last(); cur++)
cur->~TNode();
allocator::dealloc(nodes);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ class FixedMAP
return N;
}
IC u32 allocated() { return this->limit; }
IC void clear() { destroy(); }
IC void clear() { pool = 0; }
IC TNode* begin() { return nodes; }
IC TNode* end() { return nodes + pool; }
IC TNode* last() { return nodes + limit; } // for setup only
Expand Down

0 comments on commit 7fa1862

Please sign in to comment.