我是否可以在OpenGL 2.1的多个共享上下文中同时从同一缓冲区对象进行渲染? [英] Am I allowed to simultaneously render from the same buffer object on multiple shared contexts in OpenGL 2.1?

查看:166
本文介绍了我是否可以在OpenGL 2.1的多个共享上下文中同时从同一缓冲区对象进行渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apple文档中,我读到了这篇文章:

In Apple's documentation, I read this:

  • 1 — "Shared contexts share all texture objects, display lists, vertex programs, fragment programs, and buffer objects created before and after sharing is initiated."
  • 2 — "Contexts that are on different threads can share object resources. For example, it is acceptable for one context in one thread to modify a texture, and a second context in a second thread to modify the same texture. The shared object handling provided by the Apple APIs automatically protects against thread errors."

因此,我希望能够一次创建我的缓冲区对象,然后使用它们在多个上下文中同时呈现.但是,如果这样做,我的NVIDIA GeForce GT 650M会崩溃,并且回溯是这样的:

So I expected to be able to create my buffer objects once, then use them to render simultaneously on multiple contexts. However if I do that, I get crashes on my NVIDIA GeForce GT 650M with backtraces like this:

Crashed Thread:        10  Dispatch queue: com.apple.root.default-qos
Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
…
Thread 10 Crashed:: Dispatch queue: com.apple.root.default-qos
0  GLEngine  0x00007fff924111d7 gleLookupHashObject + 51
1  GLEngine  0x00007fff925019a9 gleBindBufferObject + 52
2  GLEngine  0x00007fff9243c035 glBindBuffer_Exec + 127

我已将完整的代码发布在 https://gist.github.com/jlstrecker/9df10ef177c2a49bae3e .顶部是#define SHARE_BUFFERS —注释掉它很好用,但未注释却崩溃了.

I've posted my complete code at https://gist.github.com/jlstrecker/9df10ef177c2a49bae3e. At the top, there's #define SHARE_BUFFERS — when commented out it works just fine, but uncommented it crashes.

我不想讨论是否应该使用OpenGL 2.1 —这是我正在连接的其他软件的要求.我也不想讨论是否应该使用GLUT-我的示例代码仅使用了它,因为它包含在Mac中并且没有任何外部依赖关系.我也不希望获得有关性能/优化的反馈.

I'm not looking to debate whether I should be using OpenGL 2.1 — it's a requirement of other software I'm interfacing with. Nor am I looking to debate whether I should use GLUT — my example code just uses that since it's included on Mac and doesn't have any external dependencies. Nor am I looking for feedback on performance/optimization.

我想知道是否可以期望在多个上下文中同时从单个共享缓冲区对象进行渲染,如果可以,为什么我的代码崩溃了.

I'd just like to know if I can expect to be able to simultaneously render from a single shared buffer object on multiple contexts — and if so, why my code is crashing.

推荐答案

我们还遇到了"gleLookupHashObject"崩溃问题,并做了一个小事例(非常类似于您的事例),该事例在Apple支持的事件"中发布. .经过调查,Apple DTS工程师返回了以下信息,并引述:

We also ran into the 'gleLookupHashObject' crash and made a small repro-case (very similar to yours) which was posted in an 'incident' to Apple support. After investigation, an Apple DTS engineer came back with the following info, quoting:

引起我注意的是,在主线程和绑定位置数据的辅助线程上都调用了glFlush().这确实会引入问题,尽管有些微妙,但实际上确实表明我们所施加的约束线程和GL上下文未得到充分尊重. 在这一点上,您应该进一步调查您的实现,以确保避免这种情况,或者更好的是,使用显式同步机制(例如我们为GCD提供的同步机制)扩展您的实现. "

"It came to my attention that glFlush() is being called on both the main thread and also a secondary thread that binds position data. This would indeed introduce issues and, while subtle, actually does indicate that the constraints we place on threads and GL contexts aren’t being fully respected. At this point it behoves you to either further investigate your implementation to ensure that such situations are avoided or, better yet, extend your implementation with explicit synchronization mechanisms (such as what we offer with GCD). "

因此,如果您遇到此崩溃,则需要在应用程序端进行显式同步(在驱动程序端进行修复).

So if you run into this crash you will need to do explicit synchronization on the application side (pending a fix on the driver-side).

Apple官方文档中与"OpenGL,上下文和线程"相关的摘要摘要:

Summary of relevant snippets related to "OpenGL, Contexts and Threading" from the official Apple Documentation:

[0] Section: "Use Multiple OpenGL Contexts"
If your application has multiple scenes that can be rendered in parallel, you can use a context for each scene you need to render. Create one context for each scene and assign each context to an operation or task. Because each task has its own context, all can submit rendering commands in parallel.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html#//apple_ref/doc/uid/TP40001987-CH409-SW6

[1] Section: Guidelines for Threading OpenGL Applications
(a) Use only one thread per context. OpenGL commands for a specific context are not thread safe. You should never have more than one thread accessing a single context simultaneously.
(b) Contexts that are on different threads can share object resources. For example, it is acceptable for one context in one thread to modify a texture, and a second context in a second thread to modify the same texture. The shared object handling provided by the Apple APIs automatically protects against thread errors. And, your application is following the "one thread per context" guideline.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html

[2] OpenGL Restricts Each Context to a Single Thread
Each thread in an OS X process has a single current OpenGL rendering context. Every time your application calls an OpenGL function, OpenGL implicitly looks up the context associated with the current thread and modifies the state or objects associated with that context.
OpenGL is not reentrant. If you modify the same context from multiple threads simultaneously, the results are unpredictable. Your application might crash or it might render improperly. If for some reason you decide to set more than one thread to target the same context, then you must synchronize threads by placing a mutex around all OpenGL calls to the context, such as gl* and CGL*. OpenGL commands that blockâsuch as fence commandsâdo not synchronize threads.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_threading/opengl_threading.html

这篇关于我是否可以在OpenGL 2.1的多个共享上下文中同时从同一缓冲区对象进行渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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