MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / CopyGpuToCpu

Method CopyGpuToCpu

GTE/Graphics/DX11/DX11Buffer.cpp:78–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78bool 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
104void DX11Buffer::CopyGpuToGpu(ID3D11DeviceContext* context, ID3D11Resource* target)
105{

Callers

nothing calls this directly

Calls 5

GetNumActiveBytesMethod · 0.80
GetElementSizeMethod · 0.80
GetOffsetMethod · 0.45
GetDataMethod · 0.45
UnmapMethod · 0.45

Tested by

no test coverage detected