在OpenGL中使用围栏同步对象 [英] Using fence sync objects in OpenGL

查看:158
本文介绍了在OpenGL中使用围栏同步对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试寻找可以在OpenGL中使用同步对象的方案.我的理解是,一旦将所有GL命令执行并实现后,一旦将同步对象放入GL命令流(使用glFenceSync()),就会发出信号. 如果同步对象是同步原语,为什么我们不能手动发送信号呢?该功能到底可以在哪里帮助GL程序员?

I am trying to look for scenarios where Sync Objects can be used in OpenGL. My understanding is that a sync object once put in GL command stream ( using glFenceSync() ) will be signaled after all the GL commands are executed and realized. If the sync objects are synchronization primitives why can't we MANUALLY signal them ? Where exactly this functionality can help GL programmer ?

以下情况是正确的情况吗?

Is the following scenario a correct one ?

Thread 1 :

Load model
Draw()
glFenceSync()

Thread 2 :

glWaitSync();
ReadPixels
Use data for subsequent operation.

这是否意味着除非在线程1中调用glFenceSync(),否则我无法启动线程2?

Does this mean that I can't launch thread 2 unless glFenceSync() is called in Thread 1 ?

推荐答案

围栏并不是要同步线程,而是要知道异步操作何时完成.例如,如果对像素缓冲区对象(PBO)进行glReadPixels,则可能甚至在尝试从客户端的地址空间读取PBO或将其映射到客户端地址空间之前就已经知道读取已完成.

Fences are not so much meant to synchronize threads, but to know, when asynchronus operations are finished. For example if you do a glReadPixels into a pixel buffer object (PBO), you might want to know, that the read has been completed, before you even attempt to read from or map the PBO to client address space.

如果您以PBO为目标执行glReadPixels,则呼叫将立即返回,但数据传输确实需要一些时间.那是栅栏派上用场的地方.

If you do a glReadPixels with a PBO being the target, the call will return immediately, but the data transfer may indeed take some time. That's where fences come in handy.

这篇关于在OpenGL中使用围栏同步对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆