Archive for December, 2014

Understanding OpenGL programs internals

For a start, you will need to understand lots of terms: GLX, OpenGL, DRI, DRM etc. Lookup here:

for the definition.

Looking up resources in internet (eg,, or just search "" for python implementation of torus drawing using OpenGL),

The heart of the program can summarized as follows:


0.0, 0.0, 10.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0)

glRotatef(xrot, 1.0, 0.0, 0.0)
glRotatef(yrot, 0.0, 1.0, 0.0)
glRotatef(zrot, 0.0, 0.0, 1.0)

glColor3f(0.5, 0.0, 1.0)

And the drawing as follow:

Using gdb to attach to the python program:

#0 0x00007fa60b4acb90 in __poll_nocancel ()
at ../sysdeps/unix/syscall-template.S:81
#1 0x00007fa607d12b72 in ?? () from /usr/lib/x86_64-linux-gnu/
#2 0x00007fa607d143ff in ?? () from /usr/lib/x86_64-linux-gnu/
#3 0x00007fa607d14512 in xcb_wait_for_reply ()
from /usr/lib/x86_64-linux-gnu/
#4 0x00007fa60898c48f in _XReply () from /usr/lib/x86_64-linux-gnu/>
#5 0x00007fa60970c673 in ?? () from /usr/lib/x86_64-linux-gnu/mesa/
#6 0x00007fa60970a02b in ?? () from /usr/lib/x86_64-linux-gnu/mesa/
#7 0x00007fa60263a9a9 in ?? () from /usr/lib/x86_64-linux-gnu/dri/
#8 0x00007fa60263adc3 in ?? () from /usr/lib/x86_64-linux-gnu/dri/
#9 0x00007fa60262f8f5 in ?? () from /usr/lib/x86_64-linux-gnu/dri/
#30 0x000000000055c594 in PyEval_EvalCodeEx ()
#31 0x00000000005b7392 in PyEval_EvalCode ()
#32 0x0000000000469663 in ?? ()
#33 0x00000000004699e3 in PyRun_FileExFlags ()
#34 0x0000000000469f1c in PyRun_SimpleFileExFlags ()
#35 0x000000000046ab81 in Py_Main ()
#36 0x00007fa60b3e0ec5 in __libc_start_main (main=0x46ac3f <main>, argc=2,
argv=0x7fff7d08c1e8, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fff7d08c1d8) at libc-start.c:287
#37 0x000000000057497e in _start ()

The legacy of X protocol as shown below (


And underlying the packet exchange:


Here "_XReply" is an X extension API as documented here:

and here:

As defined above: _XReply does: "Flushes the output buffer, waits for a reply packet, and copies the contents into the specified Reply parameter."

And the modern implementation is this (inside src/xcb_io.c of libX11-1.6.2 from Ubuntu’s source code repository):

* _XReply - Wait for a reply packet and copy its contents into the
* specified rep.
* extra: number of 32-bit words expected after the reply
* discard: should I discard data following "extra" words?
Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard)
xcb_generic_error_t *error;
xcb_connection_t *c = dpy->xcb->connection;
char *reply;
PendingRequest *current;

which is implemented using XCB API (vs Xlib in the past, which uses lots of locks, and thus is slow). And further understanding XCB protocol (notice the mention of lockless protocol):

And the public API is documented here:

Doing a search for the packages:

apt-file search

libgl1-mesa-dev: /usr/lib/x86_64-linux-gnu/
libgl1-mesa-dev: /usr/lib/x86_64-linux-gnu/mesa/
libgl1-mesa-glx: /usr/lib/x86_64-linux-gnu/mesa/

So, based on above, if you do a "apt-get source libgl1-mesa-dev" you will see that you end up with the Mesa source code.

From the stack trace above, we see that the Mesa component is implemented on top of _XReply API (X extension):

For example, is the glx init screen:

glx_screen_init(struct glx_screen *psc,
int screen, struct glx_display * priv)
/* Initialize per screen dynamic client GLX extensions */
psc->ext_list_first_time = GL_TRUE;
psc->scr = screen;
psc->dpy = priv->dpy;
psc->display = priv;

getVisualConfigs(psc, priv, screen);
getFBConfigs(psc, priv, screen);

return GL_TRUE;

where getVisualConfigs():

static GLboolean
getVisualConfigs(struct glx_screen *psc,
struct glx_display *priv, int screen)
xGLXGetVisualConfigsReq *req;
xGLXGetVisualConfigsReply reply;
Display *dpy = priv->dpy;


psc->visuals = NULL;
GetReq(GLXGetVisualConfigs, req);
req->reqType = priv->majorOpcode;
req->glxCode = X_GLXGetVisualConfigs;
req->screen = screen;

if (!_XReply(dpy, (xReply *) & reply, 0, False))
goto out;

psc->visuals = createConfigsFromProperties(dpy,
screen, GL_FALSE);

return psc->visuals != NULL;

And here are the relation between GLX and OpenGL (OpenGL extension):


And trying to understanding the Mesa source tree downloaded:

From above both the OpenGL and DRI drivers will talk to Nouveau modules directly:

And the kernel modules loaded:

lsmod |grep nouv

nouveau 1097199 0
mxm_wmi 13021 1 nouveau
ttm 85150 1 nouveau
drm_kms_helper 55071 2 i915,nouveau
drm 303102 7 ttm,i915,drm_kms_helper,nouveau
i2c_algo_bit 13413 2 i915,nouveau
wmi 19177 3 mxm_wmi,nouveau,asus_wmi
video 19476 3 i915,nouveau,asus_wmi

Another way of looking at some ofl the libraries called by the python program:

(gdb) info sharedlibrary


More OpenCL introductions

and the video is here:

OpenCL history:

Both the internals of OpenCL and “Clover” (OpenCL over Gallium) history are explained.

Here below are further development from Apple:

Classic sequence of calls:

clGetPlatformIDs ( [ . . . ] ) ;

clGetDeviceIDs ( [ . . . ] ) ;
clCreateContext ( [ . . . ] ) ;
clCreateCommandQueue ( [ . . . ] ) ;
clCreateProgramWithSource ( [ . . . ] ) ;
clBuildProgram ( [ . . . ] ) ;
clCreateKernel ( [ . . . ] ) ;
clCreateBuffer ( [ . . . ] ) ;
clSetKernelArg ( [ . . . ] ) ;
clEnqueueNDRangeKernel ( [ . . . ] ) ;
c l F i n i s h ( [ . . . ] ) ;
clEnqueueReadBuffer ( [ . . . ] );

OpenCL vs OpenGL Compute Shaders:

Libclc implementation:

Current status of OpenCL in Nouveau (


(AMD development on OpenCL “AMDGPU”)


Accelerating a climate physics model with OpenCL

Good overview:

A study on Shaders /GLSL

Shader vs OpenCL:

Unboxing my HackRF One

Reading “Getting Started with the HackRF One on Ubuntu 14.04”:

Starting from freshly installed Ubuntu 14.04 LTS 64-bit, something missing in the above blog (explained below) is this:

sudo apt-get install librtlsdr-dev

Next is to download all the three git tree.

While doing the cmake of “gr-osmosdr”:

cmake ../

CMake Error at CMakeLists.txt:151 (find_package):
Could not find a configuration file for package “Gnuradio” that is
compatible with requested version “3.7.3”.

The following configuration files were considered but not accepted:


cmake/gnuradio/GnuradioConfig.cmake, version:

— Configuring incomplete, errors occurred!

So no choice but to use the original webpage’s changeset version (notice there is a one digit difference between mine and his ….. guess it is an error in his webpage).

For gr-osmosdr, to get the older version:

git checkout  58d95b51

And then continue with cmake/make/make install etc.

Got the following errors:

—   package ‘gnuradio-fcdproplus’ not found
— gnuradio-fcdproplus not found.
— checking for module ‘libosmosdr’
—   package ‘libosmosdr’ not found
— libosmosdr not found.
— checking for module ‘librtlsdr’
—   package ‘librtlsdr’ not found
— librtlsdr not found.
— checking for module ‘libmirisdr’
—   package ‘libmirisdr’ not found
— libmirisdr not found.
— checking for module ‘libhackrf’
—   found libhackrf, version 0.3
— Found LIBHACKRF: /usr/local/lib/
— checking for module ‘libairspy’
—   package ‘libairspy’ not found
— checking for module ‘libbladeRF’
—   package ‘libbladeRF’ not found
— libbladeRF not found.
— Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE)
— Found PythonLibs: /usr/lib/x86_64-linux-gnu/ (found suitable version “2.7.6”, minimum required is “2”)

I ignored all the errors, except for one: librtlsdr, which I have to apt-get thus:

sudo apt-get install librtlsdr-dev

After the gqrx download and qmake, everything got running, on the latest changeset (today is 21 Dec 2014).

Inline image 1
There is another way for Ubuntu/Fedora as well:
And run the script.   It will build all the necessary binaries – completed successfully for both Fedora 20 and Ubuntu 14.04.

Essentially it will install every “hackrf_xxxxx” command, but not gqrx itself.   So using “hackrf_transfer” to capture the radio wave, and then followed by installing a third party tool “Baudline” it is possible to render the radio waves as well.   For details please refer to:

I did also tried direct “apt-get” for the following:

gqrx-sdr – Software defined radio receiver
gr-osmosdr – Gnuradio blocks from the OsmoSDR project
hackrf – Software defined radio peripheral
libhackrf-dev – Software defined radio peripheral
libhackrf0 – Software defined radio peripheral

For gqrx, after apt-get, I got the following errors:

gqrx: symbol lookup error:

Many places recorded the same errors:

Upgrading using RPi:

Similarly for Fedora 20, “sudo yum install gqrx”  will install all the dependencies for gqrx, (essentially gr-osmosdr, and rtl-sdr, and gnuradio), but executing “gqrx” does not bring up and QT screen at all.

Docker vs VM vs Vagrant vs LXC (see diagram below)

Different forms of hypervisor:

Glue for all:


OpenCL internals

Learning all about Gallium3D

Good overview:

%d bloggers like this: