Skip to content

Commit

Permalink
Revert "xrRender_RX: removed software processor from details manager"
Browse files Browse the repository at this point in the history
This reverts commit 71b5db5.
  • Loading branch information
Xottab-DUTY committed Apr 20, 2023
1 parent 1eb1afc commit 493e30e
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 10 deletions.
19 changes: 14 additions & 5 deletions src/Layers/xrRender/DetailManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ CDetailManager::CDetailManager() : xrc("detail manager")
{
dtFS = nullptr;
dtSlots = nullptr;
soft_Geom = nullptr;
hw_Geom = nullptr;
hw_BatchSize = 0;
m_time_rot_1 = 0;
Expand Down Expand Up @@ -194,7 +195,11 @@ void CDetailManager::Load()
// Make dither matrix
bwdithermap(2, dither);

hw_Load();
// Hardware specific optimizations
if (UseVS())
hw_Load();
else
soft_Load();

// swing desc
// normal
Expand All @@ -213,7 +218,10 @@ void CDetailManager::Load()
#endif
void CDetailManager::Unload()
{
hw_Unload();
if (UseVS())
hw_Unload();
else
soft_Unload();

for (CDetail* detailObject : objects)
{
Expand Down Expand Up @@ -390,9 +398,10 @@ void CDetailManager::Render()

RCache.set_CullMode(CULL_NONE);
RCache.set_xform_world(Fidentity);

hw_Render();

if (UseVS())
hw_Render();
else
soft_Render();
RCache.set_CullMode(CULL_CCW);

g_pGamePersistent->m_pGShaderConstants->m_blender_mode.w = 0.0f; //--#SM+#-- Флаг конца рендера травы [end of grass render]
Expand Down
7 changes: 7 additions & 0 deletions src/Layers/xrRender/DetailManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class ECORE_API CDetailManager
virtual ObjectList* GetSnapList() = 0;
#endif

bool UseVS() { return HW.Caps.geometry_major >= 1; }
// Software processor
ref_geom soft_Geom;
void soft_Load();
void soft_Unload();
void soft_Render();

// Hardware processor
ref_geom hw_Geom;
size_t hw_BatchSize;
Expand Down
17 changes: 12 additions & 5 deletions src/Layers/xrRender/DetailManager_Decompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,24 @@ gray255[3] = 255.f*float(c_pal->a3)/15.f;

// Vis-sorting
#ifndef DBG_SWITCHOFF_RANDOMIZE
if (Dobj->m_Flags.is(DO_NO_WAVING))
if (!UseVS())
{
// Always still on CPU pipe
Item.vis_ID = 0;
}
else
{
if (::Random.randI(0, 3) == 0)
Item.vis_ID = 2; // Second wave
if (Dobj->m_Flags.is(DO_NO_WAVING))
Item.vis_ID = 0;
else
Item.vis_ID = 1; // First wave
{
if (::Random.randI(0, 3) == 0)
Item.vis_ID = 2; // Second wave
else
Item.vis_ID = 1; // First wave
}
}
#else
// Always still on CPU pipe
Item.vis_ID = 0;
#endif
// Save it
Expand Down
174 changes: 174 additions & 0 deletions src/Layers/xrRender/DetailManager_soft.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include "stdafx.h"
#pragma hdrstop

#include "detailmanager.h"

const u32 vs_size = 3000;

void CDetailManager::soft_Load()
{
R_ASSERT(RCache.Vertex.Buffer());
R_ASSERT(RCache.Index.Buffer());
// Vertex Stream
soft_Geom.create(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, RCache.Vertex.Buffer(), RCache.Index.Buffer());
}

void CDetailManager::soft_Unload() { soft_Geom.destroy(); }
void CDetailManager::soft_Render()
{
// Render itself
// float fPhaseRange = PI/16;
// float fPhaseX = _sin(RDEVICE.fTimeGlobal*0.1f) *fPhaseRange;
// float fPhaseZ = _sin(RDEVICE.fTimeGlobal*0.11f)*fPhaseRange;

// Get index-stream
_IndexStream& _IS = RCache.Index;
_VertexStream& _VS = RCache.Vertex;
for (u32 O = 0; O < objects.size(); O++)
{
CDetail& Object = *objects[O];
u32 vCount_Object = Object.number_vertices;
u32 iCount_Object = Object.number_indices;

xr_vector<SlotItemVec*>& _vis = m_visibles[0][O];
xr_vector<SlotItemVec*>::iterator _vI = _vis.begin();
xr_vector<SlotItemVec*>::iterator _vE = _vis.end();
for (; _vI != _vE; _vI++)
{
SlotItemVec* items = *_vI;
u32 vCount_Total = items->size() * vCount_Object;
// calculate lock count needed
u32 lock_count = vCount_Total / vs_size;
if (vCount_Total > (lock_count * vs_size))
lock_count++;

// calculate objects per lock
u32 o_total = items->size();
u32 o_per_lock = o_total / lock_count;
if (o_total > (o_per_lock * lock_count))
o_per_lock++;

// Fill VB (and flush it as nesessary)
RCache.set_Shader(Object.shader);

Fmatrix mXform;
for (u32 L_ID = 0; L_ID < lock_count; L_ID++)
{
// Calculate params
u32 item_start = L_ID * o_per_lock;
u32 item_end = item_start + o_per_lock;
if (item_end > o_total)
item_end = o_total;
if (item_end <= item_start)
break;
u32 item_range = item_end - item_start;

// Calc Lock params
u32 vCount_Lock = item_range * vCount_Object;
u32 iCount_Lock = item_range * iCount_Object;

// Lock buffers
u32 vBase, iBase, iOffset = 0;
CDetail::fvfVertexOut* vDest =
(CDetail::fvfVertexOut*)_VS.Lock(vCount_Lock, soft_Geom->vb_stride, vBase);
u16* iDest = (u16*)_IS.Lock(iCount_Lock, iBase);

// Filling itself
for (u32 item_idx = item_start; item_idx < item_end; ++item_idx)
{
SlotItem& Instance = *items->at(item_idx);
float scale = Instance.scale_calculated;

// Build matrix
Fmatrix& M = Instance.mRotY;
mXform._11 = M._11 * scale;
mXform._12 = M._12 * scale;
mXform._13 = M._13 * scale;
mXform._14 = M._14;
mXform._21 = M._21 * scale;
mXform._22 = M._22 * scale;
mXform._23 = M._23 * scale;
mXform._24 = M._24;
mXform._31 = M._31 * scale;
mXform._32 = M._32 * scale;
mXform._33 = M._33 * scale;
mXform._34 = M._34;
mXform._41 = M._41;
mXform._42 = M._42;
mXform._43 = M._43;
mXform._44 = 1;

// Transfer vertices
{
u32 C = 0xffffffff;
CDetail::fvfVertexIn *srcIt = Object.vertices,
*srcEnd = Object.vertices + Object.number_vertices;
CDetail::fvfVertexOut* dstIt = vDest;

for (; srcIt != srcEnd; srcIt++, dstIt++)
{
mXform.transform_tiny(dstIt->P, srcIt->P);
dstIt->C = C;
dstIt->u = srcIt->u;
dstIt->v = srcIt->v;
}
}

// Transfer indices (in 32bit lines)
VERIFY(iOffset < 65535);
{
u32 item = (iOffset << 16) | iOffset;
u32 count = Object.number_indices / 2;
LPDWORD sit = LPDWORD(Object.indices);
LPDWORD send = sit + count;
LPDWORD dit = LPDWORD(iDest);
for (; sit != send; dit++, sit++)
*dit = *sit + item;
if (Object.number_indices & 1)
{
iDest[Object.number_indices - 1] =
(u16)(Object.indices[Object.number_indices - 1] + u16(iOffset));
}
}

// Increment counters
vDest += vCount_Object;
iDest += iCount_Object;
iOffset += vCount_Object;
}
_VS.Unlock(vCount_Lock, soft_Geom->vb_stride);
_IS.Unlock(iCount_Lock);

// Render
u32 dwNumPrimitives = iCount_Lock / 3;
RCache.set_Geometry(soft_Geom);
RCache.Render(D3DPT_TRIANGLELIST, vBase, 0, vCount_Lock, iBase, dwNumPrimitives);
}
}
// Clean up
_vis.clear();
}
}

/*
VERIFY(sizeof(CDetail::fvfVertexOut)==soft_Geom->vb_stride);
CDetail::fvfVertexOut* dstIt = vDest;
VERIFY(items->size()*Object.number_vertices==vCount_Lock);
for (u32 k = 0; k<vCount_Lock; k++)
{
// Transfer vertices
{
u32 C = 0xffffffff;
CDetail::fvfVertexIn* srcIt = Object.vertices;
CDetail::fvfVertexIn* srcEnd = Object.vertices+Object.number_vertices;
CDetail::fvfVertexOut* dstIt = vDest;
for (; srcIt!=srcEnd; srcIt++, dstIt++)
{
mXform.transform_tiny(dstIt->P, srcIt->P);
dstIt->C = C;
dstIt->u = srcIt->u;
dstIt->v = srcIt->v;
}
}
}
*/
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<ClCompile Include="..\xrRender\DetailManager.cpp" />
<ClCompile Include="..\xrRender\DetailManager_CACHE.cpp" />
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp" />
<ClCompile Include="..\xrRender\DetailManager_soft.cpp" />
<ClCompile Include="..\xrRender\DetailModel.cpp" />
<ClCompile Include="..\xrRender\dxParticleCustom.cpp" />
<ClCompile Include="..\xrRender\ETextureParams.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_soft.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailModel.cpp">
<Filter>Details</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<ClCompile Include="..\xrRender\DetailManager.cpp" />
<ClCompile Include="..\xrRender\DetailManager_CACHE.cpp" />
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp" />
<ClCompile Include="..\xrRender\DetailManager_soft.cpp" />
<ClCompile Include="..\xrRender\DetailManager_VS.cpp" />
<ClCompile Include="..\xrRender\DetailModel.cpp" />
<ClCompile Include="..\xrRender\du_box.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_soft.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_VS.cpp">
<Filter>Details</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<ClCompile Include="..\xrRender\DetailManager.cpp" />
<ClCompile Include="..\xrRender\DetailManager_CACHE.cpp" />
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp" />
<ClCompile Include="..\xrRender\DetailManager_soft.cpp" />
<ClCompile Include="..\xrRender\DetailManager_VS.cpp" />
<ClCompile Include="..\xrRender\DetailModel.cpp" />
<ClCompile Include="..\xrRender\du_box.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_soft.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_VS.cpp">
<Filter>Details</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
<ClCompile Include="..\xrRender\DetailManager.cpp" />
<ClCompile Include="..\xrRender\DetailManager_CACHE.cpp" />
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp" />
<ClCompile Include="..\xrRender\DetailManager_soft.cpp" />
<ClCompile Include="..\xrRender\DetailManager_VS.cpp" />
<ClCompile Include="..\xrRender\DetailModel.cpp" />
<ClCompile Include="..\xrRender\du_box.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@
<ClCompile Include="..\xrRender\DetailManager_Decompress.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_soft.cpp">
<Filter>Details</Filter>
</ClCompile>
<ClCompile Include="..\xrRender\DetailManager_VS.cpp">
<Filter>Details</Filter>
</ClCompile>
Expand Down

1 comment on commit 493e30e

@Xottab-DUTY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.