Skip to content

Commit bf0e420

Browse files
committed
Improve main render target detection for older Atelier games
1 parent e05d2a1 commit bf0e420

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

impl.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ class DeviceWrapper final : public ID3D11Device, IDXGIDevice1 {
874874
// Not shadow texture
875875
MSAACandidateState state = MSAACandidateState::None;
876876
UINT size = sizeof(state);
877-
if (FAILED(tex->GetPrivateData(IID_MSAACandidate, &size, &state)) || state == MSAACandidateState::None)
878-
tex->SetPrivateData(IID_MSAACandidate, sizeof(state), &MSAACandidateStatePossible);
877+
if (FAILED(pResource->GetPrivateData(IID_MSAACandidate, &size, &state)) || state == MSAACandidateState::None)
878+
pResource->SetPrivateData(IID_MSAACandidate, sizeof(state), &MSAACandidateStatePossible);
879879
}
880880
tex->Release();
881881
}
@@ -1175,11 +1175,37 @@ class ContextWrapper final : public ID3D11DeviceContext {
11751175
D3D11_DEVICE_CONTEXT_TYPE GetType() override { return ctx->GetType(); }
11761176
UINT GetContextFlags() override { return ctx->GetContextFlags(); }
11771177

1178+
void UpdateRenderTargetMSAAStatus() {
1179+
// Sophie seems to only use indexed draws on the main RT, shadow texture, and a texture where they pre-blend ground tiles
1180+
// There's usually only 10-20 ground tile draws, so target 64 as a safe number to avoid the ground tile draws
1181+
if (config.msaaSamples > 1 && numIndexedDraws > 64) {
1182+
ID3D11DepthStencilView* dsv = nullptr;
1183+
ID3D11RenderTargetView* rtv = nullptr;
1184+
MSAACandidateState state = MSAACandidateState::None;
1185+
UINT size = sizeof(state);
1186+
ctx->OMGetRenderTargets(1, &rtv, &dsv);
1187+
if (rtv && dsv) {
1188+
ID3D11Resource* rtvtex = nullptr;
1189+
rtv->GetResource(&rtvtex);
1190+
if (SUCCEEDED(rtvtex->GetPrivateData(IID_MSAACandidate, &size, &state)) && state == MSAACandidateState::Possible) {
1191+
rtvtex->SetPrivateData(IID_MSAACandidate, sizeof(state), &MSAACandidateStateProbable);
1192+
log("Marking texture with ", std::dec, numIndexedDraws, " indexed draws as MSAA target");
1193+
}
1194+
rtvtex->Release();
1195+
}
1196+
1197+
if (dsv) dsv->Release();
1198+
if (rtv) rtv->Release();
1199+
}
1200+
numIndexedDraws = 0;
1201+
}
1202+
11781203
HRESULT FinishCommandList(BOOL RestoreDeferredContextState, ID3D11CommandList** ppCommandList) override {
11791204
if (needsResolve) {
11801205
resolveIfMSAA(ctx, needsResolve);
11811206
needsResolve = nullptr;
11821207
}
1208+
UpdateRenderTargetMSAAStatus();
11831209
return ctx->FinishCommandList(RestoreDeferredContextState, ppCommandList);
11841210
}
11851211

@@ -1523,27 +1549,7 @@ class ContextWrapper final : public ID3D11DeviceContext {
15231549
updateRtvShadowResources(ctx);
15241550
rtsizeDirty = true;
15251551

1526-
// Sophie seems to only use indexed draws on the main RT, shadow texture, and a texture where they pre-blend ground tiles
1527-
// There's usually only 10-20 ground tile draws, so target 64 as a safe number to avoid the ground tile draws
1528-
if (config.msaaSamples > 1 && numIndexedDraws > 64) {
1529-
ID3D11DepthStencilView* dsv = nullptr;
1530-
ID3D11RenderTargetView* rtv = nullptr;
1531-
MSAACandidateState state = MSAACandidateState::None;
1532-
UINT size = sizeof(state);
1533-
ctx->OMGetRenderTargets(1, &rtv, &dsv);
1534-
if (rtv && dsv) {
1535-
ID3D11Resource* rtvtex = nullptr;
1536-
rtv->GetResource(&rtvtex);
1537-
if (SUCCEEDED(rtvtex->GetPrivateData(IID_MSAACandidate, &size, &state)) && state == MSAACandidateState::Possible) {
1538-
rtvtex->SetPrivateData(IID_MSAACandidate, sizeof(state), &MSAACandidateStateProbable);
1539-
log("Marking texture with ", std::dec, numIndexedDraws, " indexed draws as MSAA target");
1540-
}
1541-
rtvtex->Release();
1542-
}
1543-
if (dsv) dsv->Release();
1544-
if (rtv) rtv->Release();
1545-
}
1546-
numIndexedDraws = 0;
1552+
UpdateRenderTargetMSAAStatus();
15471553

15481554
ID3D11RenderTargetView* msaaTex = nullptr;
15491555
ID3D11DepthStencilView* msaaDepth = nullptr;

0 commit comments

Comments
 (0)