Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Layers/xrRender/Blender_Recorder_R2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void CBlender_Compile::r_Pass(LPCSTR _vs, LPCSTR _ps, bool bFog, BOOL bZtest, BO
void CBlender_Compile::r_Constant(LPCSTR name, R_constant_setup* s)
{
R_ASSERT(s);
ref_constant C = ctable.get(name);
R_constant* C = ctable.get(name);
if (C) C->handler = s;
}

Expand Down Expand Up @@ -80,7 +80,7 @@ u32 CBlender_Compile::i_Sampler(LPCSTR _name)
fix_texture_name(name);

// Find index
ref_constant C = ctable.get(name);
R_constant* C = ctable.get(name);
if (!C) return u32(-1);

R_ASSERT(C->type == RC_sampler);
Expand Down
40 changes: 20 additions & 20 deletions src/Layers/xrRender/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,16 @@ class ECORE_API CBackend
IC void set_Scissor(Irect* rect = NULL);

// constants
ICF ref_constant get_c(LPCSTR n)
ICF R_constant* get_c(LPCSTR n)
{
if (ctable) return ctable->get(n);
else return 0;
else return nullptr;
}

ICF ref_constant get_c(shared_str& n)
ICF R_constant* get_c(shared_str& n)
{
if (ctable) return ctable->get(n);
else return 0;
else return nullptr;
}

// constants - direct (fast)
Expand All @@ -380,37 +380,37 @@ class ECORE_API CBackend


// constants - LPCSTR (slow)
ICF void set_c(LPCSTR n, const Fmatrix& A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(LPCSTR n, const Fvector4& A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(LPCSTR n, float x, float y, float z, float w) { if (ctable) set_c(&*ctable->get(n), x, y, z, w); }
ICF void set_ca(LPCSTR n, u32 e, const Fmatrix& A) { if (ctable) set_ca(&*ctable->get(n), e, A); }
ICF void set_ca(LPCSTR n, u32 e, const Fvector4& A) { if (ctable) set_ca(&*ctable->get(n), e, A); }
ICF void set_c(LPCSTR n, const Fmatrix& A) { if (ctable) set_c(ctable->get(n), A); }
ICF void set_c(LPCSTR n, const Fvector4& A) { if (ctable) set_c(ctable->get(n), A); }
ICF void set_c(LPCSTR n, float x, float y, float z, float w) { if (ctable) set_c(ctable->get(n), x, y, z, w); }
ICF void set_ca(LPCSTR n, u32 e, const Fmatrix& A) { if (ctable) set_ca(ctable->get(n), e, A); }
ICF void set_ca(LPCSTR n, u32 e, const Fvector4& A) { if (ctable) set_ca(ctable->get(n), e, A); }
ICF void set_ca(LPCSTR n, u32 e, float x, float y, float z, float w)
{
if (ctable) set_ca(&*ctable->get(n), e, x, y, z, w);
if (ctable) set_ca(ctable->get(n), e, x, y, z, w);
}
#if defined(USE_DX10) || defined(USE_DX11)
ICF void set_c(LPCSTR n, float A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(LPCSTR n, int A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(LPCSTR n, float A) { if (ctable) set_c(ctable->get(n), A); }
ICF void set_c(LPCSTR n, int A) { if (ctable) set_c(ctable->get(n), A); }
#endif // USE_DX10

// constants - shared_str (average)
ICF void set_c(shared_str& n, const Fmatrix& A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(shared_str& n, const Fvector4& A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(shared_str& n, const Fmatrix& A) { if (ctable) set_c(ctable->get(n), A); }
ICF void set_c(shared_str& n, const Fvector4& A) { if (ctable) set_c(ctable->get(n), A); }
ICF void set_c(shared_str& n, float x, float y, float z, float w)
{
if (ctable) set_c(&*ctable->get(n), x, y, z, w);
if (ctable) set_c(ctable->get(n), x, y, z, w);
}

ICF void set_ca(shared_str& n, u32 e, const Fmatrix& A) { if (ctable) set_ca(&*ctable->get(n), e, A); }
ICF void set_ca(shared_str& n, u32 e, const Fvector4& A) { if (ctable) set_ca(&*ctable->get(n), e, A); }
ICF void set_ca(shared_str& n, u32 e, const Fmatrix& A) { if (ctable) set_ca(ctable->get(n), e, A); }
ICF void set_ca(shared_str& n, u32 e, const Fvector4& A) { if (ctable) set_ca(ctable->get(n), e, A); }
ICF void set_ca(shared_str& n, u32 e, float x, float y, float z, float w)
{
if (ctable) set_ca(&*ctable->get(n), e, x, y, z, w);
if (ctable) set_ca(ctable->get(n), e, x, y, z, w);
}
#if defined(USE_DX10) || defined(USE_DX11)
ICF void set_c(shared_str& n, float A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(shared_str& n, int A) { if (ctable) set_c(&*ctable->get(n), A); }
ICF void set_c(shared_str& n, float A) { if (ctable) set_c(ctable->get(n), A); }
ICF void set_c(shared_str& n, int A) { if (ctable) set_c(ctable->get(n), A); }
#endif // USE_DX10

ICF void Render(D3DPRIMITIVETYPE T, u32 baseV, u32 startV, u32 countV, u32 startI, u32 PC);
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/SkeletonX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ void CSkeletonX::_Render(ref_geom& hGeom, u32 vCount, u32 iOffset, u32 pCount)
case RM_SKINNING_4B:
{
// Transfer matrices ( current and previous )
ref_constant array = RCache.get_c(s_bones_array_const);
ref_constant array_prev = RCache.get_c(s_bones_array_prev_const);
R_constant* array = RCache.get_c(s_bones_array_const);
R_constant* array_prev = RCache.get_c(s_bones_array_prev_const);

u32 count = RMS_bonecount;
for (u32 mid = 0; mid < count; mid++)
Expand Down
13 changes: 6 additions & 7 deletions src/Layers/xrRender/r_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,24 @@ IC bool p_sort(ref_constant C1, ref_constant C2)
return xr_strcmp(C1->name, C2->name) < 0;
}

ref_constant R_constant_table::get(LPCSTR S)
R_constant* R_constant_table::get(LPCSTR S)
{
// assumption - sorted by name
c_table::iterator I = std::lower_bound(table.begin(), table.end(), S, p_search);
if (I == table.end() || (0 != xr_strcmp(*(*I)->name, S))) return 0;
else return *I;
if (I == table.end() || (0 != xr_strcmp(*(*I)->name, S))) return nullptr;
else return &**I;
}

ref_constant R_constant_table::get(shared_str& S)
R_constant* R_constant_table::get(shared_str& S)
{
// linear search, but only ptr-compare
c_table::iterator I = table.begin();
c_table::iterator E = table.end();
for (; I != E; ++I)
{
ref_constant C = *I;
if (C->name.equal(S)) return C;
if ((*I)->name.equal(S)) return &**I;
}
return 0;
return nullptr;
}

#if !defined(USE_DX10) && !defined(USE_DX11)
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRender/r_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ class ECORE_API R_constant_table : public xr_resource_flagged
void clear();
BOOL parse(void* desc, u32 destination);
void merge(R_constant_table* C);
ref_constant get(LPCSTR name); // slow search
ref_constant get(shared_str& name); // fast search
R_constant* get(LPCSTR name); // slow search
R_constant* get(shared_str& name); // fast search

BOOL equal(R_constant_table& C);
BOOL equal(R_constant_table* C) { return equal(*C); }
Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderDX10/Blender_Recorder_R3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void CBlender_Compile::r_dx10Texture(LPCSTR ResourceName, LPCSTR texture)
fix_texture_name(TexName);

// Find index
ref_constant C = ctable.get(ResourceName);
R_constant* C = ctable.get(ResourceName);
//VERIFY(C);
if (!C) return;

Expand Down Expand Up @@ -121,7 +121,7 @@ u32 CBlender_Compile::r_dx10Sampler(LPCSTR ResourceName)

// Find index
//ref_constant C = ctable.get(ResourceName);
ref_constant C = ctable.get(name);
R_constant* C = ctable.get(name);
//VERIFY(C);
if (!C) return u32(-1);

Expand Down
4 changes: 2 additions & 2 deletions src/Layers/xrRenderDX10/dx10R_Backend_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,10 @@ ICF void CBackend::ApplyRTandZB()

IC void CBackend::get_ConstantDirect(shared_str& n, u32 DataSize, void** pVData, void** pGData, void** pPData)
{
ref_constant C = get_c(n);
R_constant* C = get_c(n);

if (C)
constants.access_direct(&*C, DataSize, pVData, pGData, pPData);
constants.access_direct(C, DataSize, pVData, pGData, pPData);
else
{
if (pVData) *pVData = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_R2/r2.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class CRender : public R_dsgraph_structure

IC void apply_lmaterial()
{
R_constant* C = &*RCache.get_c(c_sbase); // get sampler
R_constant* C = RCache.get_c(c_sbase); // get sampler
if (0 == C) return;
VERIFY(RC_dest_sampler == C->destination);
VERIFY(RC_sampler == C->type);
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_R3/r3.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class CRender : public R_dsgraph_structure

IC void apply_lmaterial()
{
R_constant* C = &*RCache.get_c(c_sbase); // get sampler
R_constant* C = RCache.get_c(c_sbase); // get sampler
if (0 == C) return;
VERIFY(RC_dest_sampler == C->destination);
VERIFY(RC_dx10texture == C->type);
Expand Down
6 changes: 3 additions & 3 deletions src/Layers/xrRenderPC_R4/CSCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ CSCompiler& CSCompiler::defSampler(LPCSTR ResourceName, const D3D_SAMPLER_DESC&
{
VERIFY(ResourceName);

ref_constant C = m_constants.get(ResourceName);
R_constant* C = m_constants.get(ResourceName);
if (!C) return *this;

R_ASSERT(C->type == RC_sampler);
Expand All @@ -130,7 +130,7 @@ CSCompiler& CSCompiler::defOutput(LPCSTR ResourceName, ref_rt rt)
VERIFY(ResourceName);
if (!rt) return *this;

ref_constant C = m_constants.get(ResourceName);
R_constant* C = m_constants.get(ResourceName);
if (!C) return *this;

R_ASSERT(C->type == RC_dx11UAV);
Expand All @@ -150,7 +150,7 @@ CSCompiler& CSCompiler::defTexture(LPCSTR ResourceName, ref_texture texture)
if (!texture) return *this;

// Find index
ref_constant C = m_constants.get(ResourceName);
R_constant* C = m_constants.get(ResourceName);
if (!C) return *this;

R_ASSERT(C->type == RC_dx10texture);
Expand Down
6 changes: 3 additions & 3 deletions src/Layers/xrRenderPC_R4/ComputeShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ ComputeShader::~ComputeShader()
m_Samplers[i]->Release();
}

u32 GetCB(ref_constant C)
u32 GetCB(R_constant* C)
{
return (C->destination & RC_dest_pixel_cb_index_mask) >> RC_dest_pixel_cb_index_shift;
}


ComputeShader& ComputeShader::set_c(shared_str name, const Fvector4& value)
{
ref_constant c = m_ctable->get(name);
m_ctable->m_CBTable[GetCB(c)].second->set(&*c, c->ps, value);
R_constant* c = m_ctable->get(name);
m_ctable->m_CBTable[GetCB(c)].second->set(c, c->ps, value);
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRenderPC_R4/r4.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class CRender : public R_dsgraph_structure

IC void apply_lmaterial()
{
R_constant* C = &*RCache.get_c(c_sbase); // get sampler
R_constant* C = RCache.get_c(c_sbase); // get sampler
if (0 == C) return;
VERIFY(RC_dest_sampler == C->destination);
VERIFY(RC_dx10texture == C->type);
Expand Down
34 changes: 34 additions & 0 deletions src/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@
#include <string>

XRCORE_API xrCore Core;
XRCORE_API refcount_stats g_refcount_stats;

#include <algorithm>
void refcount_stats::dump_top_callers()
{
// Collect non-zero entries
struct entry { uintptr_t addr; u64 count; };
xr_vector<entry> entries;
entries.reserve(256);
for (u32 i = 0; i < ADDR_SLOTS; ++i)
{
u64 c = addr_table[i].count.load(std::memory_order_relaxed);
uintptr_t a = addr_table[i].addr.load(std::memory_order_relaxed);
if (c > 0 && a != 0)
entries.push_back({a, c});
}
// Sort by count descending
std::sort(entries.begin(), entries.end(), [](const entry& a, const entry& b) { return a.count > b.count; });
// Print top 20
u32 n = std::min((u32)entries.size(), 20u);
Msg("~ REFCOUNT TOP %u callers of _inc():", n);
for (u32 i = 0; i < n; ++i)
Msg("~ #%2u: %12llu calls ret_addr=0x%p", i + 1, entries[i].count, (void*)entries[i].addr);
}

void refcount_stats::reset_addrs()
{
for (u32 i = 0; i < ADDR_SLOTS; ++i)
{
addr_table[i].addr.store(0, std::memory_order_relaxed);
addr_table[i].count.store(0, std::memory_order_relaxed);
}
}

extern XRCORE_API u32 build_id;
extern XRCORE_API LPCSTR build_date;

Expand Down