2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
7
// MappedSubresourceVerifier11.cpp: Implements the
8
// rx::MappedSubresourceVerifier11 class, a simple wrapper to D3D11 Texture2D
9
// mapped memory so that ASAN and MSAN can catch memory errors done with a
10
// pointer to the mapped texture memory.
12
#include "libANGLE/renderer/d3d/d3d11/MappedSubresourceVerifier11.h"
14
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
19
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || defined(ANGLE_ENABLE_ASSERTS)
24
# if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER)
25
constexpr bool kUseWrap = true;
27
constexpr bool kUseWrap = false;
30
size_t getPitchCount(const D3D11_TEXTURE2D_DESC &desc)
32
const d3d11::DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(desc.Format);
33
ASSERT(desc.Height % dxgiFormatInfo.blockHeight == 0);
34
return desc.Height / dxgiFormatInfo.blockHeight;
39
MappedSubresourceVerifier11::MappedSubresourceVerifier11() = default;
41
MappedSubresourceVerifier11::~MappedSubresourceVerifier11()
44
ASSERT(!mWrapData.size());
47
void MappedSubresourceVerifier11::setDesc(const D3D11_TEXTURE2D_DESC &desc)
49
ASSERT(desc.CPUAccessFlags & (D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE));
53
ASSERT(!mWrapData.size());
56
mPitchType = &D3D11_MAPPED_SUBRESOURCE::RowPitch;
57
mPitchCount = getPitchCount(desc);
60
void MappedSubresourceVerifier11::setDesc(const D3D11_TEXTURE3D_DESC &desc)
62
ASSERT(desc.CPUAccessFlags & (D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE));
67
ASSERT(!mWrapData.size());
70
mPitchType = &D3D11_MAPPED_SUBRESOURCE::DepthPitch;
71
mPitchCount = desc.Depth;
74
void MappedSubresourceVerifier11::reset()
77
ASSERT(!mWrapData.size());
82
bool MappedSubresourceVerifier11::wrap(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map)
84
ASSERT(map && map->pData);
85
ASSERT(mapType == D3D11_MAP_READ || mapType == D3D11_MAP_WRITE ||
86
mapType == D3D11_MAP_READ_WRITE);
91
if (!mWrapData.resize(mPitchCount * map->*mPitchType))
95
mOrigData = reinterpret_cast<uint8_t *>(map->pData);
99
std::copy(mOrigData, mOrigData + mWrapData.size(), mWrapData.data());
100
map->pData = mWrapData.data();
105
void MappedSubresourceVerifier11::unwrap()
111
std::copy(mWrapData.data(), mWrapData.data() + mWrapData.size(), mOrigData);
112
mWrapData = angle::MemoryBuffer();