当尝试使用 glBufferSubData 访问 GL_ARRAY_BUFFER 到 128 字节缓冲区大小时,访问最多需要 200 微秒。相反,当使用 glBufferData 再次分配整个缓冲区时,它只需要 3 微秒。我对 glGetBufferSubData 有类似的问题。我的 CPU 是 i5 8600k,GPU 是 gtx 1080 ti
glBufferData(GL_ARRAY_BUFFER, sizeof(mat4) * 2, matrices.data(), GL_DYNAMIC_DRAW); // 3 us
glBufferSubData(GL_ARRAY_BUFFER, sizeof(mat4) * index, sizeof(mat4), matrix.data()); // at worst 200 us
using namespace std::chrono;
// same measurement for both cases
auto timer = high_resolution_clock::now();
glBufferData(GL_ARRAY_BUFFER, sizeof(mat4) * 2, matrices.data(), GL_DYNAMIC_DRAW);
std::cout << duration_cast<microseconds>(high_resolution_clock::now() - timer).count() << '\n';
最佳答案
这个问题可能早该回答了,但今天我正在考虑使用 glGetBufferSubData 并注意到尽管运行了 NVidia GEFORCE RTX 3060 还是有点滞后。有 0.006 秒的时间将数据下载到 CPU/RAM 和 0第二次加载到GPU。我建议在 RAM 中保留矩阵的拷贝,并将矩阵所在位置的索引存储在着色器存储缓冲区中,以便您以后可以根据需要在程序中更新它。至少这就是我正在做的事情。
你可以在这里看到我的原始帖子:Is it efficient to download matrix to CPU/RAM to update it and send it back to GPU?
https://stackoverflow.com/questions/62655935/
相关文章:
react-native - 当应用程序已经安装时,如何从 React Native 中的实际应用程
node.js - 如何在服务器端渲染中使用 Mongodb
c# - CreatedAtAction 结果为 "No route matches the sup
google-apps-script - 如何使用 GAS 获取文档中的 URL 并将其替换为 UR
python - 如何使用环境变量设置 boto3 连接超时和读取超时?
python-3.x - Python中存在数值数据时如何解决TypeError : 'No Num
node.js - NodeMailer - G-Suite - 服务账户 - 以群组邮件形式发送