Skip to content

Commit 4a76ded

Browse files
committed
Implemented mipmap bias control for R3-R4.
1 parent a0c7726 commit 4a76ded

File tree

11 files changed

+49
-43
lines changed

11 files changed

+49
-43
lines changed

src/Layers/xrRender/r__dsgraph_build.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,15 +837,16 @@ void D3DXRenderBase::Reset(HWND hWnd, u32& dwWidth, u32& dwHeight, float& fWidth
837837
void D3DXRenderBase::SetupStates()
838838
{
839839
HW.Caps.Update();
840-
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
841-
// TODO: DX10: Implement Resetting of render states into default mode
842-
// VERIFY(!"D3DXRenderBase::SetupStates not implemented.");
840+
#if defined(USE_OGL)
841+
// TODO: OGL: Implement SetupStates().
842+
#elif defined(USE_DX10) || defined(USE_DX11)
843+
SSManager.SetMaxAnisotropy(ps_r__tf_Anisotropic);
844+
SSManager.SetMipLODBias(ps_r__tf_Mipbias);
843845
#else // USE_DX10
844846
for (u32 i = 0; i < HW.Caps.raster.dwStages; i++)
845847
{
846-
float fBias = -.5f;
847-
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 4));
848-
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MIPMAPLODBIAS, *(LPDWORD)&fBias));
848+
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, ps_r__tf_Anisotropic));
849+
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MIPMAPLODBIAS, *(LPDWORD)&ps_r__tf_Mipbias));
849850
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR));
850851
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR));
851852
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR));

src/Layers/xrRender/xrRender_console.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ float ps_r__ssaDONTSORT = 32.f; // RO
100100
float ps_r__ssaHZBvsTEX = 96.f; // RO
101101

102102
int ps_r__tf_Anisotropic = 8;
103+
float ps_r__tf_Mipbias = 0.0f;
103104

104105
// R1
105106
float ps_r1_ssaLOD_A = 64.f;
106107
float ps_r1_ssaLOD_B = 48.f;
107-
float ps_r1_tf_Mipbias = 0.0f;
108108
Flags32 ps_r1_flags = {R1FLAG_DLIGHTS}; // r1-only
109109
float ps_r1_lmodel_lerp = 0.1f;
110110
float ps_r1_dlights_clip = 40.f;
@@ -119,7 +119,6 @@ int ps_r1_SoftwareSkinning = 0; // r1-only
119119
// R2
120120
float ps_r2_ssaLOD_A = 64.f;
121121
float ps_r2_ssaLOD_B = 48.f;
122-
float ps_r2_tf_Mipbias = 0.0f;
123122

124123
// R2-specific
125124
Flags32 ps_r2_ls_flags = {R2FLAG_SUN
@@ -299,9 +298,10 @@ class CCC_tf_MipBias : public CCC_Float
299298
if (nullptr == HW.pDevice)
300299
return;
301300

302-
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
303-
// TODO: DX10: Implement mip bias control
304-
//VERIFY(!"apply not implmemented.");
301+
#if defined(USE_OGL)
302+
// TODO: OGL: Implement mipmap bias control.
303+
#elif defined(USE_DX10) || defined(USE_DX11)
304+
SSManager.SetMipLODBias(*value);
305305
#else // USE_DX10
306306
for (u32 i = 0; i < HW.Caps.raster.dwStages; i++)
307307
CHK_DX(HW.pDevice->SetSamplerState(i, D3DSAMP_MIPMAPLODBIAS, *((LPDWORD)value)));
@@ -725,12 +725,12 @@ void xrRender_initconsole()
725725
#endif // DEBUG
726726

727727
CMD2(CCC_tf_Aniso, "r__tf_aniso", &ps_r__tf_Anisotropic); // {1..16}
728+
CMD2(CCC_tf_MipBias, "r__tf_mipbias", &ps_r__tf_Mipbias); // {-3 +3}
728729

729730
// R1
730731
CMD4(CCC_Float, "r1_ssa_lod_a", &ps_r1_ssaLOD_A, 16, 96);
731732
CMD4(CCC_Float, "r1_ssa_lod_b", &ps_r1_ssaLOD_B, 16, 64);
732733
CMD4(CCC_Float, "r1_lmodel_lerp", &ps_r1_lmodel_lerp, 0, 0.333f);
733-
CMD2(CCC_tf_MipBias, "r1_tf_mipbias", &ps_r1_tf_Mipbias); // {-3 +3}
734734
CMD3(CCC_Mask, "r1_dlights", &ps_r1_flags, R1FLAG_DLIGHTS);
735735
CMD4(CCC_Float, "r1_dlights_clip", &ps_r1_dlights_clip, 10.f, 150.f);
736736
CMD4(CCC_Float, "r1_pps_u", &ps_r1_pps_u, -1.f, +1.f);
@@ -751,7 +751,6 @@ void xrRender_initconsole()
751751
// R2
752752
CMD4(CCC_Float, "r2_ssa_lod_a", &ps_r2_ssaLOD_A, 16, 96);
753753
CMD4(CCC_Float, "r2_ssa_lod_b", &ps_r2_ssaLOD_B, 32, 64);
754-
CMD2(CCC_tf_MipBias, "r2_tf_mipbias", &ps_r2_tf_Mipbias);
755754

756755
// R2-specific
757756
CMD2(CCC_R2GM, "r2em", &ps_r2_gmaterial);
@@ -920,14 +919,4 @@ void xrRender_initconsole()
920919
//CMD3(CCC_Mask, "r2_sun_ignore_portals", &ps_r2_ls_flags, R2FLAG_SUN_IGNORE_PORTALS);
921920
}
922921

923-
void xrRender_apply_tf()
924-
{
925-
Console->Execute("r__tf_aniso");
926-
#if RENDER == R_R1
927-
Console->Execute("r1_tf_mipbias");
928-
#else
929-
Console->Execute("r2_tf_mipbias");
930-
#endif
931-
}
932-
933922
#endif

src/Layers/xrRender/xrRender_console.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ extern ECORE_API float ps_r__ssaDISCARD;
5454
extern ECORE_API float ps_r__ssaDONTSORT;
5555
extern ECORE_API float ps_r__ssaHZBvsTEX;
5656
extern ECORE_API int ps_r__tf_Anisotropic;
57+
extern ECORE_API float ps_r__tf_Mipbias;
5758

5859
// R1
5960
extern ECORE_API float ps_r1_ssaLOD_A;
6061
extern ECORE_API float ps_r1_ssaLOD_B;
61-
extern ECORE_API float ps_r1_tf_Mipbias;
6262
extern ECORE_API float ps_r1_lmodel_lerp;
6363
extern ECORE_API float ps_r1_dlights_clip;
6464
extern ECORE_API float ps_r1_pps_u;
@@ -79,7 +79,6 @@ enum
7979
// R2
8080
extern ECORE_API float ps_r2_ssaLOD_A;
8181
extern ECORE_API float ps_r2_ssaLOD_B;
82-
extern ECORE_API float ps_r2_tf_Mipbias;
8382

8483
// R2-specific
8584
extern ECORE_API Flags32 ps_r2_ls_flags; // r2-only
@@ -209,6 +208,5 @@ enum
209208

210209
extern void xrRender_initconsole();
211210
extern BOOL xrRender_test_hw();
212-
extern void xrRender_apply_tf();
213211

214212
#endif

src/Layers/xrRenderDX10/StateManager/dx10SamplerStateCache.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using dx10StateUtils::operator==;
66

77
dx10SamplerStateCache SSManager;
88

9-
dx10SamplerStateCache::dx10SamplerStateCache() : m_uiMaxAnisotropy(1)
9+
dx10SamplerStateCache::dx10SamplerStateCache() : m_uiMaxAnisotropy(1), m_uiMipLODBias(0.0f)
1010
{
1111
static const int iMaxRSStates = 10;
1212
m_StateArray.reserve(iMaxRSStates);
@@ -20,6 +20,8 @@ dx10SamplerStateCache::SHandle dx10SamplerStateCache::GetState(D3D_SAMPLER_DESC&
2020
// MaxAnisitropy is reset by ValidateState if not aplicable
2121
// to the filter mode used.
2222
desc.MaxAnisotropy = m_uiMaxAnisotropy;
23+
// RZ
24+
desc.MipLODBias = m_uiMipLODBias;
2325

2426
dx10StateUtils::ValidateState(desc);
2527

@@ -140,7 +142,7 @@ void dx10SamplerStateCache::CSApplySamplers(HArray& samplers)
140142
}
141143
#endif
142144

143-
void dx10SamplerStateCache::SetMaxAnisotropy(UINT uiMaxAniso)
145+
void dx10SamplerStateCache::SetMaxAnisotropy(u32 uiMaxAniso)
144146
{
145147
clamp(uiMaxAniso, (u32)1, (u32)16);
146148

@@ -168,3 +170,26 @@ void dx10SamplerStateCache::SetMaxAnisotropy(UINT uiMaxAniso)
168170
CreateState(desc, &rec.m_pState);
169171
}
170172
}
173+
174+
void dx10SamplerStateCache::SetMipLODBias(float uiMipLODBias)
175+
{
176+
if (m_uiMipLODBias == uiMipLODBias)
177+
return;
178+
179+
m_uiMipLODBias = uiMipLODBias;
180+
181+
for (u32 i = 0; i < m_StateArray.size(); ++i)
182+
{
183+
StateRecord& rec = m_StateArray[i];
184+
StateDecs desc;
185+
186+
rec.m_pState->GetDesc(&desc);
187+
188+
desc.MipLODBias = m_uiMipLODBias;
189+
dx10StateUtils::ValidateState(desc);
190+
191+
// This can cause fragmentation if called too often
192+
rec.m_pState->Release();
193+
CreateState(desc, &rec.m_pState);
194+
}
195+
}

src/Layers/xrRenderDX10/StateManager/dx10SamplerStateCache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class dx10SamplerStateCache
3131
void CSApplySamplers(HArray& samplers);
3232
#endif
3333

34-
void SetMaxAnisotropy(UINT uiMaxAniso);
34+
void SetMaxAnisotropy(u32 uiMaxAniso);
35+
void SetMipLODBias(float uiMipLODBias);
3536

3637
private:
3738
typedef ID3DSamplerState IDeviceState;
@@ -55,6 +56,7 @@ class dx10SamplerStateCache
5556
xr_vector<StateRecord> m_StateArray;
5657

5758
u32 m_uiMaxAnisotropy;
59+
float m_uiMipLODBias;
5860
};
5961

6062
extern dx10SamplerStateCache SSManager;

src/Layers/xrRenderDX10/dx10StateUtils.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ bool operator==(const D3D_SAMPLER_DESC& desc1, const D3D_SAMPLER_DESC& desc2)
340340
return false;
341341
if (desc1.AddressW != desc2.AddressW)
342342
return false;
343-
if (desc1.MipLODBias != desc2.MipLODBias)
344-
return false;
343+
// RZ
344+
// if (desc1.MipLODBias != desc2.MipLODBias)
345+
// return false;
345346
// Ignore anisotropy since it's set up automatically by the manager
346347
// if( desc1.MaxAnisotropy != desc2.MaxAnisotropy) return false;
347348
if (desc1.ComparisonFunc != desc2.ComparisonFunc)
@@ -457,7 +458,8 @@ u32 GetHash(const D3D_SAMPLER_DESC& desc)
457458
Hash.AddData(&desc.AddressU, sizeof(desc.AddressU));
458459
Hash.AddData(&desc.AddressV, sizeof(desc.AddressV));
459460
Hash.AddData(&desc.AddressW, sizeof(desc.AddressW));
460-
Hash.AddData(&desc.MipLODBias, sizeof(desc.MipLODBias));
461+
// RZ
462+
// Hash.AddData(&desc.MipLODBias, sizeof(desc.MipLODBias));
461463
// Ignore anisotropy since it's set up automatically by the manager
462464
// Hash.AddData( &desc.MaxAnisotropy, sizeof(desc.MaxAnisotropy) );
463465
Hash.AddData(&desc.ComparisonFunc, sizeof(desc.ComparisonFunc));

src/Layers/xrRenderPC_GL/rgl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ void CRender::create()
369369
//R_CHK (HW.pDevice->CreateQuery(D3DQUERYTYPE_EVENT,&q_sync_point[0]));
370370
//R_CHK (HW.pDevice->CreateQuery(D3DQUERYTYPE_EVENT,&q_sync_point[1]));
371371

372-
xrRender_apply_tf();
373372
PortalTraverser.initialize();
374373
// TODO: OGL: Implement FluidManager.
375374
// FluidManager.Initialize( 70, 70, 70 );
@@ -432,7 +431,6 @@ void CRender::reset_end()
432431

433432
Target = new CRenderTarget();
434433

435-
xrRender_apply_tf();
436434
//FluidManager.SetScreenSize(Device.dwWidth, Device.dwHeight);
437435

438436
// Set this flag true to skip the first render frame,

src/Layers/xrRenderPC_R1/FStaticRender.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ void CRender::create()
100100
PSLibrary.OnCreate();
101101
//. HWOCC.occq_create (occq_size);
102102

103-
xrRender_apply_tf();
104103
::PortalTraverser.initialize();
105104
}
106105

@@ -134,7 +133,6 @@ void CRender::reset_begin()
134133

135134
void CRender::reset_end()
136135
{
137-
xrRender_apply_tf();
138136
//. HWOCC.occq_create (occq_size);
139137
Target = new CRenderTarget();
140138
if (L_Projector)

src/Layers/xrRenderPC_R2/r2.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ void CRender::create()
328328
for (u32 i = 0; i < HW.Caps.iGPUNum; ++i)
329329
R_CHK(HW.pDevice->CreateQuery(D3DQUERYTYPE_EVENT, &q_sync_point[i]));
330330

331-
xrRender_apply_tf();
332331
::PortalTraverser.initialize();
333332
}
334333

@@ -404,8 +403,6 @@ void CRender::reset_end()
404403
}
405404
//-AVO
406405

407-
xrRender_apply_tf();
408-
409406
// Set this flag true to skip the first render frame,
410407
// that some data is not ready in the first frame (for example device camera position)
411408
m_bFirstFrameAfterReset = true;

src/Layers/xrRenderPC_R3/r3.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ void CRender::create()
439439
R_CHK(HW.pDevice->CreateQuery(&qdesc, &q_sync_point[i]));
440440
q_sync_point[0]->End();
441441

442-
xrRender_apply_tf();
443442
::PortalTraverser.initialize();
444443
FluidManager.Initialize(70, 70, 70);
445444
// FluidManager.Initialize( 100, 100, 100 );
@@ -527,7 +526,6 @@ void CRender::reset_end()
527526
}
528527
//-AVO
529528

530-
xrRender_apply_tf();
531529
FluidManager.SetScreenSize(Device.dwWidth, Device.dwHeight);
532530

533531
// Set this flag true to skip the first render frame,

0 commit comments

Comments
 (0)