Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLX : glXCreatePbuffer() - pbuffer allocation fails #264

Open
ajgallant opened this issue Jun 21, 2022 · 10 comments
Open

GLX : glXCreatePbuffer() - pbuffer allocation fails #264

ajgallant opened this issue Jun 21, 2022 · 10 comments
Labels
GLX An issue related to GLX (eg: mesa, indirect GLX, etc)

Comments

@ajgallant
Copy link

Summary

Off-screen, direct rendering using the pbuffer fails. Calls to glXCreatePbuffer() return the following error:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  27 (X_GLXCreatePbuffer)
  Serial number of failed request:  20
  Current serial number in output stream:  20

The call sequence in the test case provided was functioning prior to an upgrade to Mac OS X 10.15.

All FBConfigs returned by glXChooseFBConfig() for pbuffer rendering support:

  • GLX_MAX_PBUFFER_WIDTH 8192
  • GLX_MAX_PBUFFER_HEIGHT 8192
  • GLX_MAX_PBUFFER_PIXELS 0
Please find the [pbuf_render](https://github.com/ajgallant/pbuf_render "Title") test case in the github repository below.

Environment

OS: MacOS 11.1 (Big Sur)
Hardware: AMD Radeon Pro 575
X11: XQuartz 2.8.0 (xorg-server 1.19.7)

Test Case

https://github.com/ajgallant/pbuf_render

@jeremyhu
Copy link
Member

Is this a recent regression? If so, do you know what changed to introduce it?

@ajgallant
Copy link
Author

This behavior coincided with an upgrade to Mac OS X 10.15. Now that I have upgraded to MacOS 11.1 and XQuartz 2.8.0, I expected the problem to resolve itself, but it persists with the X Error : BadMatch.

The pbuf_render test application that I pushed to github should make reproducing the problem easy for the XQuartz team.

@jeremyhu
Copy link
Member

Ah right, I think I recall something about this from a few years ago. I'll see if I can dig that up.

@ajgallant
Copy link
Author

Jeremy,

pbuffer (pixel buffer) support for Mac OS seems tenuous for OpenGL 2.1 going forward. pbuffer has been deprecated and is not supported in OpenGL 3.0. From the Apple OpenGL | Drawing Offscreen guide:

Important: Pixel buffers are deprecated starting with OS X v10.7 and are not supported by the OpenGL 3.2 Core profile; use framebuffer objects instead.

I found another citation in OpenGL on the Mac Platform:

Note: A pixel buffer (pbuffer) is an OpenGL buffer designed for hardware-accelerated offscreen drawing and as a source for texturing. An application can render an image into a pixel buffer and then use the pixel buffer as a texture for other OpenGL commands. Although pixel buffers are supported on Apple’s implementation of OpenGL, Apple recommends you use framebuffer objects instead. See Drawing Offscreen for more information on offscreen rendering.

Will XQuartz continue to support pbuffer for OpenGL 2.1 or follow Mac OS?

It is possible to rewrite offscreen rendering code to use frame buffers, but I would like the XQuartz team to be aware of a pbuffer allocation issue.

@jeremyhu
Copy link
Member

To be calear, @ajgallant, there isn't really an XQuartz team. XQuartz hasn't had much development for about a decade now. I still jump in periodically to cut new releases by pulling in updated upstream sources and will try to fix simple quality of life bugs here and there, but there is nobody looking at the core architecture and driving the project forward. I've commented in many places about where I think the project should go if someone was interested, but there doesn't seem to be anyone wanting to pick it up. If you'd be interested in helping out, GLX support is a great place to jump in.

@ajgallant
Copy link
Author

Does this mean that I get to fly in and interview? Open-source is awesome! I am bringing my surfboard this time. 🏄🏽‍♂️

@jeremyhu
Copy link
Member

jeremyhu commented Jul 1, 2022

No need to fly in or interview... just send pull requests. ;)

@ajgallant
Copy link
Author

I debugged the xorg-server 1.20.14 using lldb while running the pbuf_render test case. I did not find the server making a call to dispatch_CreatePbuffer() from glx/vndcmds.c:GlxDispatchRequest() through the dispatchFuncs table as I anticipated. Instead, the OpenGL client library made a call to the vendor GLX directly and logged the following errors in lldb:

2022-07-01 20:12:36.132035-0400 pbuf_render[95948:1772105] Initializing libGL.
2022-07-01 20:12:36.132340-0400 pbuf_render[95948:1772105] CGL major 1 minor 2
2022-07-01 20:12:36.145425-0400 pbuf_render[95948:1772105] SecTaskLoadEntitlements failed error=22 cs_flags=20, pid=95948
2022-07-01 20:12:36.145494-0400 pbuf_render[95948:1772105] SecTaskCopyDebugDescription: pbuf_render[95948]/0#-1 LF=0
glXChooseFBConfig() found 160 eligible FBConfig
fbCfg[0] id: 0x69, drawable_flags: 7 (4), render_flags: 1 (1)
fbCfg[0] max: w8192 h8192 p3686400
glXCreatePbuffer() may throw an error
2022-07-01 20:12:36.148837-0400 pbuf_render[95948:1772105] apple_glx_drawable_create: new drawable 0x101811600
2022-07-01 20:12:36.151283-0400 pbuf_render[95948:1772105] destroy_drawable_callback: 0x101811600 ->reference_count before -- 1
2022-07-01 20:12:36.151303-0400 pbuf_render[95948:1772105] destroying pbuffer for drawable 0x600001
2022-07-01 20:12:36.151316-0400 pbuf_render[95948:1772105] destroy_drawable: freeing 0x101811600
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  148 (GLX)
  Minor opcode of failed request:  27 (X_GLXCreatePbuffer)
  Serial number of failed request:  20
  Current serial number in output stream:  20
Process 95948 exited with status = 1 (0x00000001) 

The output from pbuf_render and OpenGL are mixed in the above, but I believe some additional insights can be inferred from the debug messages.


Development Support

The config and build for XQuartz were easy with the developer notes on the XQuartz github site. I also found the following useful in my understanding of the X.org Server architecture:

  1. X.Org Server - describes the components of the server
  2. libglvnd: the GL Vendor-Neutral Dispatch library - OpenGL and xorg-server call vendor GL

@jeremyhu jeremyhu added the GLX An issue related to GLX (eg: mesa, indirect GLX, etc) label Dec 4, 2022
@darkaegisagain
Copy link

You could use a FBO.. but a pixel buffer is pretty simple, if your interested in a fix I could take a look. I wrote the PBuffer interface to OpenGL at Apple 20 years ago.

@ajgallant
Copy link
Author

I have been content with the FBO alternative to the deprecated pixel buffer. I prefer the additional control of render buffer and depth buffer attributes that FBO provides. I would not be interested in using pixel buffers in the future now that my project has been refactored.

Jafaral added a commit to Jafaral/unicon that referenced this issue Dec 24, 2022
PBuffer seems to be deprecated and not available as of OpenGL 3.0 on macOS.
glXCreatePbuffer fails on MacOS with this error:

```
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  149 (GLX)
  Minor opcode of failed request:  27 (X_GLXCreatePbuffer)
  Serial number of failed request:  35
  Current serial number in output stream:  35
```

So the GL 2D implementation still needs a fix, but this patch allows
3D graphics to work again at least. see:

XQuartz/XQuartz#264

Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GLX An issue related to GLX (eg: mesa, indirect GLX, etc)
Projects
None yet
Development

No branches or pull requests

3 participants