| 47 | } |
| 48 | |
| 49 | bool DX11Buffer::CopyCpuToGpu(ID3D11DeviceContext* context) |
| 50 | { |
| 51 | PreparedForCopy(D3D11_CPU_ACCESS_WRITE); |
| 52 | |
| 53 | Buffer* buffer = GetBuffer(); |
| 54 | UINT numActiveBytes = buffer->GetNumActiveBytes(); |
| 55 | if (numActiveBytes > 0) |
| 56 | { |
| 57 | // Map the staging buffer. |
| 58 | D3D11_MAPPED_SUBRESOURCE sub; |
| 59 | DX11Log(context->Map(mStaging, 0, D3D11_MAP_WRITE, 0, &sub)); |
| 60 | |
| 61 | // Copy from CPU memory to staging buffer. For buffers, the |
| 62 | // 'box' members are specified in number of bytes. The inputs |
| 63 | // 'DstX', 'DstY', and 'DstZ' are also specified in number of bytes. |
| 64 | uint32_t offsetInBytes = buffer->GetOffset() * buffer->GetElementSize(); |
| 65 | char const* source = buffer->GetData() + offsetInBytes; |
| 66 | char* target = reinterpret_cast<char*>(sub.pData) + offsetInBytes; |
| 67 | std::memcpy(target, source, numActiveBytes); |
| 68 | context->Unmap(mStaging, 0); |
| 69 | |
| 70 | // Copy from staging buffer to GPU memory. TODO: It seems that |
| 71 | // buffer->GetOffset() should play a role in the copy. |
| 72 | D3D11_BOX box = { offsetInBytes, 0, 0, offsetInBytes + numActiveBytes, 1, 1 }; |
| 73 | context->CopySubresourceRegion(GetDXBuffer(), 0, offsetInBytes, 0, 0, mStaging, 0, &box); |
| 74 | } |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | bool DX11Buffer::CopyGpuToCpu(ID3D11DeviceContext* context) |
| 79 | { |
nothing calls this directly
no test coverage detected