| 128 | } |
| 129 | |
| 130 | bool DX11Texture::CopyGpuToCpu(ID3D11DeviceContext* context, uint32_t sri) |
| 131 | { |
| 132 | Texture* texture = GetTexture(); |
| 133 | LogAssert(sri < texture->GetNumSubresources(), "Subresource index out of range."); |
| 134 | PreparedForCopy(D3D11_CPU_ACCESS_READ); |
| 135 | |
| 136 | // Copy from GPU memory to staging texture. |
| 137 | ID3D11Resource* dxTexture = GetDXResource(); |
| 138 | context->CopySubresourceRegion(mStaging, sri, 0, 0, 0, dxTexture, sri, nullptr); |
| 139 | |
| 140 | // Map the staging texture. |
| 141 | D3D11_MAPPED_SUBRESOURCE sub; |
| 142 | DX11Log(context->Map(mStaging, sri, D3D11_MAP_READ, 0, &sub)); |
| 143 | |
| 144 | // Copy from staging texture to CPU memory. |
| 145 | auto sr = texture->GetSubresource(sri); |
| 146 | uint32_t numDimensions = texture->GetNumDimensions(); |
| 147 | if (numDimensions == 1) |
| 148 | { |
| 149 | std::memcpy(sr.data, sub.pData, texture->GetNumBytesFor(sr.level)); |
| 150 | } |
| 151 | else if (numDimensions == 2) |
| 152 | { |
| 153 | CopyPitched2(texture->GetDimensionFor(sr.level, 1), sub.RowPitch, |
| 154 | sub.pData, sr.rowPitch, sr.data); |
| 155 | } |
| 156 | else // numDimensions == 3 |
| 157 | { |
| 158 | CopyPitched3(texture->GetDimensionFor(sr.level, 1), |
| 159 | texture->GetDimensionFor(sr.level, 2), sub.RowPitch, |
| 160 | sub.DepthPitch, sub.pData, sr.rowPitch, sr.slicePitch, sr.data); |
| 161 | } |
| 162 | context->Unmap(mStaging, sri); |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | bool DX11Texture::CopyGpuToCpu(ID3D11DeviceContext* context) |
| 167 | { |
nothing calls this directly
no test coverage detected