| 71 | } |
| 72 | |
| 73 | bool DX11Texture::CopyCpuToGpu(ID3D11DeviceContext* context, uint32_t sri) |
| 74 | { |
| 75 | Texture* texture = GetTexture(); |
| 76 | LogAssert(sri < texture->GetNumSubresources(), "Subresource index out of range."); |
| 77 | PreparedForCopy(D3D11_CPU_ACCESS_WRITE); |
| 78 | |
| 79 | // Map the staging texture. |
| 80 | D3D11_MAPPED_SUBRESOURCE sub; |
| 81 | DX11Log(context->Map(mStaging, sri, D3D11_MAP_WRITE, 0, &sub)); |
| 82 | |
| 83 | // Copy from CPU memory to staging texture. |
| 84 | auto sr = texture->GetSubresource(sri); |
| 85 | uint32_t numDimensions = texture->GetNumDimensions(); |
| 86 | if (numDimensions == 1) |
| 87 | { |
| 88 | std::memcpy(sub.pData, sr.data, texture->GetNumBytesFor(sr.level)); |
| 89 | } |
| 90 | else if (numDimensions == 2) |
| 91 | { |
| 92 | CopyPitched2(texture->GetDimensionFor(sr.level, 1), sr.rowPitch, |
| 93 | sr.data, sub.RowPitch, sub.pData); |
| 94 | } |
| 95 | else // numDimensions == 3 |
| 96 | { |
| 97 | CopyPitched3(texture->GetDimensionFor(sr.level, 1), |
| 98 | texture->GetDimensionFor(sr.level, 2), sr.rowPitch, |
| 99 | sr.slicePitch, sr.data, sub.RowPitch, sub.DepthPitch, |
| 100 | sub.pData); |
| 101 | } |
| 102 | context->Unmap(mStaging, sri); |
| 103 | |
| 104 | // Copy from staging texture to GPU memory. |
| 105 | ID3D11Resource* dxTexture = GetDXResource(); |
| 106 | context->CopySubresourceRegion(dxTexture, sri, 0, 0, 0, mStaging, sri, nullptr); |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | bool DX11Texture::CopyCpuToGpu(ID3D11DeviceContext* context) |
| 111 | { |
nothing calls this directly
no test coverage detected