| 76 | } |
| 77 | |
| 78 | bool DX11Buffer::CopyGpuToCpu(ID3D11DeviceContext* context) |
| 79 | { |
| 80 | PreparedForCopy(D3D11_CPU_ACCESS_READ); |
| 81 | |
| 82 | Buffer* buffer = GetBuffer(); |
| 83 | UINT numActiveBytes = buffer->GetNumActiveBytes(); |
| 84 | if (numActiveBytes > 0) |
| 85 | { |
| 86 | // Copy from GPU memory to staging buffer. |
| 87 | uint32_t offsetInBytes = buffer->GetOffset() * buffer->GetElementSize(); |
| 88 | D3D11_BOX box = { offsetInBytes, 0, 0, offsetInBytes + numActiveBytes, 1, 1 }; |
| 89 | context->CopySubresourceRegion(mStaging, 0, offsetInBytes, 0, 0, GetDXBuffer(), 0, &box); |
| 90 | |
| 91 | // Map the staging buffer. |
| 92 | D3D11_MAPPED_SUBRESOURCE sub; |
| 93 | DX11Log(context->Map(mStaging, 0, D3D11_MAP_READ, 0, &sub)); |
| 94 | |
| 95 | // Copy from staging buffer to CPU memory. |
| 96 | char const* source = reinterpret_cast<char*>(sub.pData) + offsetInBytes; |
| 97 | char* target = buffer->GetData() + offsetInBytes; |
| 98 | std::memcpy(target, source, numActiveBytes); |
| 99 | context->Unmap(mStaging, 0); |
| 100 | } |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | void DX11Buffer::CopyGpuToGpu(ID3D11DeviceContext* context, ID3D11Resource* target) |
| 105 | { |
nothing calls this directly
no test coverage detected