@@ -834,11 +834,28 @@ class DeviceWrapper final : public ID3D11Device, IDXGIDevice1 {
834
834
835
835
HRESULT STDMETHODCALLTYPE CreateSamplerState (const D3D11_SAMPLER_DESC* pSamplerDesc, ID3D11SamplerState** ppSamplerState) override {
836
836
D3D11_SAMPLER_DESC desc = *pSamplerDesc;
837
+ bool modified = false ;
837
838
if (config.anisotropy && desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR) {
838
839
desc.Filter = D3D11_FILTER_ANISOTROPIC;
839
840
desc.MaxAnisotropy = config.anisotropy ;
841
+ modified = true ;
840
842
}
841
- return dev->CreateSamplerState (&desc, ppSamplerState);
843
+ float bias;
844
+ if (config.lodBias < 0 )
845
+ bias = std::max (config.lodBias , config.lodBias + desc.MipLODBias );
846
+ else
847
+ bias = std::min (config.lodBias , config.lodBias + desc.MipLODBias );
848
+ if (bias != desc.MipLODBias ) {
849
+ desc.MipLODBias = bias;
850
+ modified = true ;
851
+ }
852
+ HRESULT hr = dev->CreateSamplerState (&desc, ppSamplerState);
853
+ if (SUCCEEDED (hr)) {
854
+ ID3D11SamplerState* orig;
855
+ if (SUCCEEDED (dev->CreateSamplerState (pSamplerDesc, &orig)))
856
+ (*ppSamplerState)->SetPrivateDataInterface (IID_OriginalShader, orig);
857
+ }
858
+ return hr;
842
859
}
843
860
844
861
HRESULT STDMETHODCALLTYPE CreateShaderResourceView (ID3D11Resource* pResource, const D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc, ID3D11ShaderResourceView** ppSRView) override {
@@ -1039,7 +1056,10 @@ class ContextWrapper final : public ID3D11DeviceContext {
1039
1056
ID3D11BlendState* requestedBlend = nullptr ;
1040
1057
ID3D11PixelShader* requestedPS = nullptr ;
1041
1058
D3D11_MAPPED_SUBRESOURCE lastMap;
1059
+ void * tmpMemory = nullptr ;
1060
+ UINT tmpMemorySize = 0 ;
1042
1061
UINT scissorWidth, scissorHeight, viewportWidth, viewportHeight;
1062
+ bool shouldUseOldShaders = false ;
1043
1063
bool blendStateSupportsA2C = false ;
1044
1064
bool psSupportsA2C = false ;
1045
1065
bool rtsizeDirty = false ;
@@ -1097,7 +1117,6 @@ class ContextWrapper final : public ID3D11DeviceContext {
1097
1117
1098
1118
// ID3D11DeviceContext
1099
1119
void VSSetConstantBuffers (UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const * ppConstantBuffers) override { ctx->VSSetConstantBuffers (StartSlot, NumBuffers, ppConstantBuffers); }
1100
- void PSSetSamplers (UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const * ppSamplers) override { ctx->PSSetSamplers (StartSlot, NumSamplers, ppSamplers); }
1101
1120
void VSSetShader (ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const * ppClassInstances, UINT NumClassInstances) override { ctx->VSSetShader (pVertexShader, ppClassInstances, NumClassInstances); }
1102
1121
void PSSetConstantBuffers (UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const * ppConstantBuffers) override { ctx->PSSetConstantBuffers (StartSlot, NumBuffers, ppConstantBuffers); }
1103
1122
void IASetInputLayout (ID3D11InputLayout* pInputLayout) override { ctx->IASetInputLayout (pInputLayout); }
@@ -1345,6 +1364,31 @@ class ContextWrapper final : public ID3D11DeviceContext {
1345
1364
ctx->DrawIndexedInstancedIndirect (pBufferForArgs, AlignedByteOffsetForArgs);
1346
1365
}
1347
1366
1367
+ void PSSetSamplers (UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const * ppSamplers) override {
1368
+ bool replacedSamplers = false ;
1369
+ if (shouldUseOldShaders) {
1370
+ for (UINT i = 0 ; i < NumSamplers; i++) {
1371
+ ID3D11SamplerState* orig;
1372
+ UINT size = sizeof (orig);
1373
+ if (SUCCEEDED (ppSamplers[i]->GetPrivateData (IID_OriginalShader, &size, &orig))) {
1374
+ orig->Release (); // Still being held by sampler private data
1375
+ if (!replacedSamplers) {
1376
+ replacedSamplers = true ;
1377
+ SIZE_T size = sizeof (*ppSamplers) * NumSamplers;
1378
+ if (tmpMemorySize < size) {
1379
+ tmpMemory = realloc (tmpMemory, size);
1380
+ tmpMemorySize = size;
1381
+ }
1382
+ memcpy (tmpMemory, ppSamplers, size);
1383
+ ppSamplers = static_cast <ID3D11SamplerState**>(tmpMemory);
1384
+ }
1385
+ const_cast <ID3D11SamplerState**>(ppSamplers)[i] = orig;
1386
+ }
1387
+ }
1388
+ }
1389
+ ctx->PSSetSamplers (StartSlot, NumSamplers, ppSamplers);
1390
+ }
1391
+
1348
1392
void PSSetShaderResources (UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView* const * ppShaderResourceViews) override {
1349
1393
for (UINT i = 0 ; i < NumViews; i++) {
1350
1394
if (ppShaderResourceViews[i]) {
@@ -1360,7 +1404,7 @@ class ContextWrapper final : public ID3D11DeviceContext {
1360
1404
void PSSetShader (ID3D11PixelShader* pPixelShader, ID3D11ClassInstance* const * ppClassInstances, UINT NumClassInstances) override {
1361
1405
requestedPS = pPixelShader;
1362
1406
ID3D11PixelShader* a2c = nullptr ;
1363
- bool useOriginalShaders = shouldUseOldShaders () ;
1407
+ bool useOriginalShaders = shouldUseOldShaders;
1364
1408
bool oldUseA2C = ShouldUseA2C ();
1365
1409
if (pPixelShader && !useOriginalShaders) {
1366
1410
UINT size = sizeof (a2c);
@@ -1410,6 +1454,8 @@ class ContextWrapper final : public ID3D11DeviceContext {
1410
1454
}
1411
1455
1412
1456
void ClearDepthStencilView (ID3D11DepthStencilView* pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil) override {
1457
+ // Pick something that happens fairly infrequently to update this so we don't spam XInputGetState
1458
+ shouldUseOldShaders = ::atfix::shouldUseOldShaders ();
1413
1459
if (ID3D11DepthStencilView* msaa = getMSAADSV (pDepthStencilView)) {
1414
1460
ctx->ClearDepthStencilView (msaa, ClearFlags, Depth, Stencil);
1415
1461
msaa->Release ();
0 commit comments