Please consider a donation to the Higher Intellect project. See https://preterhuman.net/donate.php or the Donate to Higher Intellect page for more info.

Purify glXMakeCurrent segfaults

From Higher Intellect Wiki
Jump to navigation Jump to search
> > I got a demo licence for purify and was trying to use it with
> > OpenGL / GLX.  The problem is that a purified executable seg
> > faults in glXMakeCurrent.  Has anybody seen this?  Even on a
> > small program that just creates a window and makes it current
> > craps out - works fine if it is not purified.  ( Not that I'm
> > not doing somthing stupid! )  Any ideas much appreciated.
> 
> I have also this problem. I'm running purify: Purify version 4.0.1 IRIX6
> on a 6.3 O2. By specifying the context as non-direct, purify
> stops complaining. 
> 
> Could someone explain why?

Yes. I can explain why.

The OpenGL implementation for SGI O2 is a highly tuned piece of software. One side effect is that there are often places where "uninitialized memory references" (UMRs in Purify speak) occur that are actually not programming errors, but actually part of heavily tuning the implementation.

What happens when you use indirect rendering is that the X server (really an OpenGL rendering thread forked within the X server address space) performs your OpenGL rendering. This means you don't see the UMRs since your program is just sending GLX protocol to the X server, not actually calling the real OpenGL rendering code.

Using indirect rendering is a "good way" to avoid getting all those Purify errors. You can also go in and tell purify to suppress various errors that occur with OpenGL.

My explanation that UMRs can actually help performance may seem dubious, so I'll go ahead and give a brief example of where they actually make sense for good performance:

typedef struct {
  int flags;
  int spanX, spanY;
  int spanLength;
  [... other structure elements not shown ...]
  int fogParam1, fogParam2, fogParam3;
} RasterInfo;

Now some routine operations by filling in the RasterInfo structure and passing a pointer to the structure to a "processRasterInfo" routine. The flags parameter actually determines what RasterInfo elements get looked at by processRasterInfo. For example:

  RasterInfo ri;

  ri.flags = ~FOG_BIT;  /* All the modes EXCEPT fog. */
  ri.spanX = x;
  ri.spanY = y;
  ri.spanLength = len;
  [... unshown structure elements filled in ...]
  
  /* Don't waste time filling in fogParam* elements! */

  processRasterInfo(&ri);

Now, the processRasterInfo would say:

  if (FOG_BIT & rip->flags) {
    /* Do fog application code; use fogParam* parameters. */
  }

The point is that the "ri" structure gets allocated on the stack, but its fogParam* elements don't ever get looked at so we don't waste time initializing them. Of course, other callers of processRasterInfo do set the FOG_BIT flag and then would appropriately fill in fogParams.

You can imagine all sorts of cases in OpenGL where modes are not enabled so the O2 OpenGL library just skips filling in information for speed.

Another reasons UMRs can occur is because SGI's OpenGL implementations often use Direct Memory Access (or DMA) whereby results from the frame buffer (like glReadPixels) is actually transferred using DMA directly into your memory. This is all done transparently to you. The problem is that purify doesn't "see" that this memory actually got updated directly be the graphics hardware so it thinks the memory is still uninitialized. Hence, this can cause a UMR when you got to look at the results returned by DMA.


SGI OpenGL implementation use memory-mapping mechanism to enable direct access from application to graphic hardware. glXMakeCurrent makes OpenGL runtime bind certain range of addresses in application address space to adaptor registers and RAM; glXSwapBuffers disconnects the application from the adaptor.

Purify, which marks all available memory as read-only, get confused on OpenGL memory mapping, resulting in a lot of meaningless error reports. One possible solution is indeed creating indirect context, another is disabling OpenGL-related error messages by insertion in .purify file 'suppress * "libGLcore.so"'.