Skip to content

Commit 98b5c9b

Browse files
committed
Properly update shadow buffers on map/unmap
Fixes text in Atelier Ayesha
1 parent 94cb8b9 commit 98b5c9b

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

impl.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ class ContextWrapper final : public ID3D11DeviceContext {
10021002
ID3D11BlendState* alphaToCoverageBlend = nullptr;
10031003
ID3D11BlendState* requestedBlend = nullptr;
10041004
ID3D11PixelShader* requestedPS = nullptr;
1005+
D3D11_MAPPED_SUBRESOURCE lastMap;
10051006
bool blendStateSupportsA2C = false;
10061007
bool psSupportsA2C = false;
10071008

@@ -1061,8 +1062,6 @@ class ContextWrapper final : public ID3D11DeviceContext {
10611062
void PSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) override { ctx->PSSetSamplers(StartSlot, NumSamplers, ppSamplers); }
10621063
void VSSetShader(ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const* ppClassInstances, UINT NumClassInstances) override { ctx->VSSetShader(pVertexShader, ppClassInstances, NumClassInstances); }
10631064
void Draw(UINT VertexCount, UINT StartVertexLocation) override { ctx->Draw(VertexCount, StartVertexLocation); }
1064-
HRESULT Map(ID3D11Resource* pResource, UINT Subresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource) override { return ctx->Map(pResource, Subresource, MapType, MapFlags, pMappedResource); }
1065-
void Unmap(ID3D11Resource* pResource, UINT Subresource) override { ctx->Unmap(pResource, Subresource); }
10661065
void PSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers) override { ctx->PSSetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); }
10671066
void IASetInputLayout(ID3D11InputLayout* pInputLayout) override { ctx->IASetInputLayout(pInputLayout); }
10681067
void IASetVertexBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppVertexBuffers, const UINT* pStrides, const UINT* pOffsets) override { ctx->IASetVertexBuffers(StartSlot, NumBuffers, ppVertexBuffers, pStrides, pOffsets); }
@@ -1151,6 +1150,41 @@ class ContextWrapper final : public ID3D11DeviceContext {
11511150
UINT GetContextFlags() override { return ctx->GetContextFlags(); }
11521151
HRESULT FinishCommandList(BOOL RestoreDeferredContextState, ID3D11CommandList** ppCommandList) override { return ctx->FinishCommandList(RestoreDeferredContextState, ppCommandList); }
11531152

1153+
HRESULT Map(ID3D11Resource* pResource, UINT Subresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource) override {
1154+
if (ID3D11Resource* shadow = getShadowResource(pResource)) {
1155+
HRESULT res = ctx->Map(shadow, Subresource, D3D11_MAP_READ_WRITE, 0, pMappedResource);
1156+
if (SUCCEEDED(res))
1157+
lastMap = *pMappedResource;
1158+
shadow->Release();
1159+
return res;
1160+
}
1161+
return ctx->Map(pResource, Subresource, MapType, MapFlags, pMappedResource);
1162+
}
1163+
1164+
void Unmap(ID3D11Resource* pResource, UINT Subresource) override {
1165+
if (ID3D11Resource* shadow = getShadowResource(pResource)) {
1166+
D3D11_MAPPED_SUBRESOURCE map;
1167+
HRESULT res = ctx->Map(pResource, Subresource, D3D11_MAP_WRITE_DISCARD, 0, &map);
1168+
if (SUCCEEDED(res)) {
1169+
ATFIX_RESOURCE_INFO info = {};
1170+
getResourceInfo(pResource, &info);
1171+
BYTE* dst = static_cast<BYTE*>(map.pData);
1172+
const BYTE* src = static_cast<const BYTE*>(lastMap.pData);
1173+
uint32_t dstPitch = map.RowPitch;
1174+
uint32_t srcPitch = lastMap.RowPitch;
1175+
uint32_t pxWide = info.Width * getFormatPixelSize(info.Format);
1176+
for (uint32_t y = 0; y < info.Height; y++) {
1177+
std::memcpy(dst, src, pxWide);
1178+
dst += dstPitch;
1179+
src += srcPitch;
1180+
}
1181+
}
1182+
ctx->Unmap(shadow, Subresource);
1183+
shadow->Release();
1184+
}
1185+
ctx->Unmap(pResource, Subresource);
1186+
}
1187+
11541188
void DrawIndexed(UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation) override {
11551189
numIndexedDraws++;
11561190
ctx->DrawIndexed(IndexCount, StartIndexLocation, BaseVertexLocation);

0 commit comments

Comments
 (0)