Example #1
0
std::vector<T> downloadForDebugging(Resource &buffer)
{
    // This function is very slow since it causes a GPU-CPU sync point,
    // but for debugging it's convenient.
    Resource downloaded = downloadForDebugging(buffer);

    size_t bytes = downloaded.bufferDescriptor().ByteWidth;
    size_t elements = bytes / sizeof(T);
    std::vector<T> v(elements);

    D3D11_MAPPED_SUBRESOURCE mapped;
    zero(mapped);
    context->Map(downloaded.buffer, 0, D3D11_MAP_READ, 0, &mapped);
    memcpy(v.data(), mapped.pData, bytes);
    context->Unmap(downloaded.buffer, 0);

    return v;
}