Skip to content

Commit 7fa1862

Browse files
intorrXottab-DUTY
authored andcommitted
Part 4 of the experiment to remove doug_lea_allocator.
1 parent 7ceaaf0 commit 7fa1862

File tree

4 files changed

+79
-87
lines changed

4 files changed

+79
-87
lines changed

src/Layers/xrRender/D3DXRenderBase.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,31 @@ class D3DXRenderBase : public IRender, public pureFrame
4747
R_dsgraph::mapSorted_T mapHUDEmissive;
4848
#endif
4949

50+
// Runtime structures
51+
xr_vector<R_dsgraph::mapNormalVS::TNode*> nrmVS;
52+
#if defined(USE_DX10) || defined(USE_DX11)
53+
xr_vector<R_dsgraph::mapNormalGS::TNode*> nrmGS;
54+
#endif // USE_DX10
55+
xr_vector<R_dsgraph::mapNormalPS::TNode*> nrmPS;
56+
xr_vector<R_dsgraph::mapNormalCS::TNode*> nrmCS;
57+
xr_vector<R_dsgraph::mapNormalStates::TNode*> nrmStates;
58+
xr_vector<R_dsgraph::mapNormalTextures::TNode*> nrmTextures;
59+
xr_vector<R_dsgraph::mapNormalTextures::TNode*> nrmTexturesTemp;
60+
61+
xr_vector<R_dsgraph::mapMatrixVS::TNode*> matVS;
62+
#if defined(USE_DX10) || defined(USE_DX11)
63+
xr_vector<R_dsgraph::mapMatrixGS::TNode*> matGS;
64+
#endif // USE_DX10
65+
xr_vector<R_dsgraph::mapMatrixPS::TNode*> matPS;
66+
xr_vector<R_dsgraph::mapMatrixCS::TNode*> matCS;
67+
xr_vector<R_dsgraph::mapMatrixStates::TNode*> matStates;
68+
xr_vector<R_dsgraph::mapMatrixTextures::TNode*> matTextures;
69+
xr_vector<R_dsgraph::mapMatrixTextures::TNode*> matTexturesTemp;
5070
xr_vector<R_dsgraph::_LodItem> lstLODs;
5171
xr_vector<int> lstLODgroups;
5272
xr_vector<ISpatial*> lstRenderables;
5373
xr_vector<ISpatial*> lstSpatial;
74+
xr_vector<dxRender_Visual*> lstVisuals;
5475

5576
u32 counter_S;
5677
u32 counter_D;
@@ -92,10 +113,25 @@ class D3DXRenderBase : public IRender, public pureFrame
92113

93114
void r_dsgraph_destroy()
94115
{
116+
nrmVS.clear();
117+
nrmPS.clear();
118+
nrmCS.clear();
119+
nrmStates.clear();
120+
nrmTextures.clear();
121+
nrmTexturesTemp.clear();
122+
123+
matVS.clear();
124+
matPS.clear();
125+
matCS.clear();
126+
matStates.clear();
127+
matTextures.clear();
128+
matTexturesTemp.clear();
129+
95130
lstLODs.clear();
96131
lstLODgroups.clear();
97132
lstRenderables.clear();
98133
lstSpatial.clear();
134+
lstVisuals.clear();
99135

100136
for (int i = 0; i < SHADER_PASSES_MAX; ++i)
101137
{

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ template <class T> IC bool cmp_textures_lexN(const T &lhs, const T &rhs)
7070
return std::lexicographical_compare(t1->begin(), t1->end(), t2->begin(), t2->end());
7171
}
7272

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

@@ -82,8 +82,6 @@ template <class T> void sort_tlist(xr_vector<T::template TNode*>& lst, T& textur
8282
}
8383
else
8484
{
85-
xr_vector<T::template TNode*> temp;
86-
8785
// Split into 2 parts
8886
for (auto &it : textures)
8987
{
@@ -123,7 +121,6 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
123121
{
124122
mapNormalVS& vs = mapNormalPasses[_priority][iPass];
125123

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

137-
xr_vector<mapNormalGS::TNode*> nrmGS;
138135
gs.getANY_P(nrmGS);
139136
std::sort(nrmGS.begin(), nrmGS.end(), cmp_val_ssa<mapNormalGS::TNode*>);
140137
for (auto & gs_it : nrmGS)
@@ -145,7 +142,8 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
145142
#else // USE_DX10
146143
mapNormalPS& ps = vs_it->val;
147144
#endif // USE_DX10
148-
xr_vector<mapNormalPS::TNode*> nrmPS;
145+
ps.ssa = 0;
146+
149147
ps.getANY_P(nrmPS);
150148
std::sort(nrmPS.begin(), nrmPS.end(), cmp_ps_val_ssa<mapNormalPS::TNode*>);
151149
for (auto &ps_it : nrmPS)
@@ -159,32 +157,34 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
159157
#else
160158
mapNormalCS& cs = ps_it->val;
161159
#endif
162-
xr_vector<mapNormalCS::TNode*> nrmCS;
160+
cs.ssa = 0;
161+
163162
cs.getANY_P(nrmCS);
164163
std::sort(nrmCS.begin(), nrmCS.end(), cmp_val_ssa<mapNormalCS::TNode*>);
165164
for (auto &cs_it : nrmCS)
166165
{
167166
RCache.set_Constants(cs_it->key);
168167

169168
mapNormalStates& states = cs_it->val;
169+
states.ssa = 0;
170170

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

178177
mapNormalTextures& tex = state_it->val;
178+
tex.ssa = 0;
179179

180-
xr_vector<mapNormalTextures::TNode*> nrmTextures;
181-
sort_tlist<mapNormalTextures>(nrmTextures, tex);
180+
sort_tlist<mapNormalTextures>(nrmTextures, nrmTexturesTemp, tex);
182181
for (auto &tex_it : nrmTextures)
183182
{
184183
RCache.set_Textures(tex_it->key);
185184
RImplementation.apply_lmaterial();
186185

187186
mapNormalItems& items = tex_it->val;
187+
items.ssa = 0;
188188

189189
std::sort(items.begin(), items.end(), cmp_ssa<_NormalItem>);
190190
for (auto &it_it : items)
@@ -197,18 +197,25 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
197197
}
198198
items.clear();
199199
}
200+
nrmTexturesTemp.clear();
201+
nrmTextures.clear();
200202
tex.clear();
201203
}
204+
nrmStates.clear();
202205
states.clear();
203206
}
207+
nrmCS.clear();
204208
cs.clear();
205209
}
210+
nrmPS.clear();
206211
ps.clear();
207212
#if defined(USE_DX10) || defined(USE_DX11)
208213
}
214+
nrmGS.clear();
209215
gs.clear();
210216
#endif // USE_DX10
211217
}
218+
nrmVS.clear();
212219
vs.clear();
213220
}
214221
}
@@ -221,7 +228,6 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
221228
{
222229
mapMatrixVS& vs = mapMatrixPasses[_priority][iPass];
223230

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

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

234-
xr_vector<mapMatrixGS::TNode*> matGS;
235241
gs.getANY_P(matGS);
236242
std::sort(matGS.begin(), matGS.end(), cmp_val_ssa<mapMatrixGS::TNode*>);
237243
for (auto &gs_it : matGS)
@@ -242,7 +248,8 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
242248
#else // USE_DX10
243249
mapMatrixPS& ps = vs_id->val;
244250
#endif // USE_DX10
245-
xr_vector<mapMatrixPS::TNode *> matPS;
251+
ps.ssa = 0;
252+
246253
ps.getANY_P(matPS);
247254
std::sort(matPS.begin(), matPS.end(), cmp_ps_val_ssa<mapMatrixPS::TNode *>);
248255
for (auto &ps_it : matPS)
@@ -256,32 +263,34 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
256263
#else
257264
mapMatrixCS& cs = ps_it->val;
258265
#endif
259-
xr_vector<mapMatrixCS::TNode*> matCS;
266+
cs.ssa = 0;
267+
260268
cs.getANY_P(matCS);
261269
std::sort(matCS.begin(), matCS.end(), cmp_val_ssa<mapMatrixCS::TNode*>);
262270
for (auto &cs_it : matCS)
263271
{
264272
RCache.set_Constants(cs_it->key);
265273

266274
mapMatrixStates& states = cs_it->val;
275+
states.ssa = 0;
267276

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

275283
mapMatrixTextures& tex = state_it->val;
284+
tex.ssa = 0;
276285

277-
xr_vector<mapMatrixTextures::TNode*> matTextures;
278-
sort_tlist<mapMatrixTextures>(matTextures, tex);
286+
sort_tlist<mapMatrixTextures>(matTextures, matTexturesTemp, tex);
279287
for (auto &tex_it : matTextures)
280288
{
281289
RCache.set_Textures(tex_it->key);
282290
RImplementation.apply_lmaterial();
283291

284292
mapMatrixItems& items = tex_it->val;
293+
items.ssa = 0;
285294

286295
std::sort(items.begin(), items.end(), cmp_ssa<_MatrixItem>);
287296
for (auto &ni_it : items)
@@ -298,18 +307,25 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
298307
}
299308
items.clear();
300309
}
310+
matTexturesTemp.clear();
311+
matTextures.clear();
301312
tex.clear();
302313
}
314+
matStates.clear();
303315
states.clear();
304316
}
317+
matCS.clear();
305318
cs.clear();
306319
}
320+
matPS.clear();
307321
ps.clear();
308322
#if defined(USE_DX10) || defined(USE_DX11)
309323
}
324+
matGS.clear();
310325
gs.clear();
311326
#endif // USE_DX10
312327
}
328+
matVS.clear();
313329
vs.clear();
314330
}
315331

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

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

609625
for (auto &it : lstVisuals)

src/xrCommon/xr_vector.h

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#pragma once
22
#include <vector>
33
#include "xrCore/Memory/xalloc.h"
4-
#include "xrCore/xrDebug_macros.h"
5-
6-
#ifdef _M_AMD64
7-
#define M_DONTDEFERCLEAR_EXT
8-
#endif
9-
10-
#define M_DONTDEFERCLEAR_EXT // for mem-debug only
114

125
#define DEF_VECTOR(N, T)\
136
typedef xr_vector<T> N;\
@@ -17,6 +10,9 @@
1710
typedef xr_vector<T> N;\
1811
typedef N::iterator I;
1912

13+
//template <typename T, typename allocator = xalloc<T>>
14+
//using xr_vector = class std::vector<T, allocator>;
15+
2016
// vector
2117
template <typename T, typename allocator = xalloc<T>>
2218
class xr_vector : public std::vector<T, allocator>
@@ -27,65 +23,9 @@ class xr_vector : public std::vector<T, allocator>
2723
using allocator_type = allocator;
2824

2925
xr_vector() : inherited() {}
26+
xr_vector(size_t _count) : inherited(_count) {}
3027
xr_vector(size_t _count, const T& _value) : inherited(_count, _value) {}
31-
explicit xr_vector(size_t _count) : inherited(_count) {}
32-
u32 size() const throw() { return (u32)inherited::size(); }
33-
34-
void clear_and_free() throw() { inherited::clear(); }
35-
void clear_not_free() { erase(begin(), end()); }
36-
void clear_and_reserve()
37-
{
38-
if (capacity() <= size() + size()/4)
39-
clear_not_free();
40-
else
41-
{
42-
u32 old = size();
43-
clear_and_free();
44-
reserve(old);
45-
}
46-
}
47-
#ifdef M_DONTDEFERCLEAR_EXT // defined (or not) by xalloc.h
48-
void clear() { clear_and_free(); }
49-
#else
50-
void clear() { clear_not_free(); }
51-
#endif
52-
const_reference operator[](size_type _Pos) const
53-
{
54-
check_idx(_Pos);
55-
return *(begin()+_Pos);
56-
}
57-
reference operator[](size_type _Pos)
58-
{
59-
check_idx(_Pos);
60-
return *(begin()+_Pos);
61-
}
62-
63-
private:
64-
void check_idx(size_type _Pos) const
65-
{
66-
VERIFY2(_Pos < size(),
67-
make_string("index is out of range: index requested[%d], size of container[%d]",
68-
_Pos, size()).c_str());
69-
}
70-
};
71-
72-
// vector<bool>
73-
template <>
74-
class xr_vector<bool, xalloc<bool>> : public std::vector<bool, xalloc<bool>>
75-
{
76-
using inherited = std::vector<bool, xalloc<bool>>;
77-
78-
public:
79-
u32 size() const { return (u32)inherited::size(); }
80-
void clear() { erase(begin(), end()); }
81-
};
82-
83-
template <typename allocator>
84-
class xr_vector<bool, allocator> : public std::vector<bool, allocator>
85-
{
86-
using inherited = std::vector<bool, allocator>;
87-
88-
public:
89-
u32 size() const { return (u32)inherited::size(); }
90-
void clear() { erase(begin(), end()); }
28+
IC void clear_and_free() { clear(); }
29+
IC void clear_not_free() { clear(); }
30+
IC void clear_and_reserve() { clear(); }
9131
};

src/xrCore/FixedMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class FixedMAP
140140
{
141141
if (nodes)
142142
{
143-
for (TNode* cur = begin(); cur != end(); cur++)
143+
for (TNode* cur = begin(); cur != last(); cur++)
144144
cur->~TNode();
145145
allocator::dealloc(nodes);
146146
}
@@ -245,7 +245,7 @@ class FixedMAP
245245
return N;
246246
}
247247
IC u32 allocated() { return this->limit; }
248-
IC void clear() { destroy(); }
248+
IC void clear() { pool = 0; }
249249
IC TNode* begin() { return nodes; }
250250
IC TNode* end() { return nodes + pool; }
251251
IC TNode* last() { return nodes + limit; } // for setup only

0 commit comments

Comments
 (0)