@@ -1002,6 +1002,7 @@ class ContextWrapper final : public ID3D11DeviceContext {
1002
1002
ID3D11BlendState* alphaToCoverageBlend = nullptr ;
1003
1003
ID3D11BlendState* requestedBlend = nullptr ;
1004
1004
ID3D11PixelShader* requestedPS = nullptr ;
1005
+ D3D11_MAPPED_SUBRESOURCE lastMap;
1005
1006
bool blendStateSupportsA2C = false ;
1006
1007
bool psSupportsA2C = false ;
1007
1008
@@ -1061,8 +1062,6 @@ class ContextWrapper final : public ID3D11DeviceContext {
1061
1062
void PSSetSamplers (UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const * ppSamplers) override { ctx->PSSetSamplers (StartSlot, NumSamplers, ppSamplers); }
1062
1063
void VSSetShader (ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const * ppClassInstances, UINT NumClassInstances) override { ctx->VSSetShader (pVertexShader, ppClassInstances, NumClassInstances); }
1063
1064
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); }
1066
1065
void PSSetConstantBuffers (UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const * ppConstantBuffers) override { ctx->PSSetConstantBuffers (StartSlot, NumBuffers, ppConstantBuffers); }
1067
1066
void IASetInputLayout (ID3D11InputLayout* pInputLayout) override { ctx->IASetInputLayout (pInputLayout); }
1068
1067
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 {
1151
1150
UINT GetContextFlags () override { return ctx->GetContextFlags (); }
1152
1151
HRESULT FinishCommandList (BOOL RestoreDeferredContextState, ID3D11CommandList** ppCommandList) override { return ctx->FinishCommandList (RestoreDeferredContextState, ppCommandList); }
1153
1152
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
+
1154
1188
void DrawIndexed (UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation) override {
1155
1189
numIndexedDraws++;
1156
1190
ctx->DrawIndexed (IndexCount, StartIndexLocation, BaseVertexLocation);
0 commit comments