Graphical corruption when using Uniform Buffer Objects on iMX6

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Graphical corruption when using Uniform Buffer Objects on iMX6

1,007 Views
hartmutbehrensf
Contributor I

Hi,

 

I've modified a Qt textures example (http://doc.qt.io/qt-5/qtopengl-textures-example.html ) to test out UBO functionality on the iMX6 (using a SABRE board with 6QP AP) - see attachment for the complete modifications. Below I have reproduced the shaders. When the example is run, a lot of graphical corruption can be seen in the spinning cubes.

 

Has anyone else experienced this ? Do you know of any workarounds / fixes ?

 

QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);

QString vsrc =

"in vec4 vertex;\n"

"in vec2 texCoord;\n"

"out vec2 texc;\n"

"uniform int rotIndex;\n"

"\n"

"int getRotoationIndex(void);\n"

"mat4 getRotationMatrix(int Index);\n"

"mat4 getRotationMatrix(void);\n"

"\n"

"struct VertexData {\n"

" mat4 rotMatrix;\n"

"};\n"

"layout(std140) uniform u_VertexData {\n"

" VertexData vData[64];\n"

"};\n"

"\n"

"int getRotationIndex(void) { return rotIndex; }\n"

"mat4 getRotationMatrix(int Index) { return vData[Index].rotMatrix; }\n"

"mat4 getRotationMatrix(void) { return getRotationMatrix(getRotationIndex()); }\n"

"\n"

"void main(void)\n"

"{\n"

" mat4 rotMatrix = getRotationMatrix(rotIndex);\n"

" gl_Position = rotMatrix * vertex;\n"

" texc = texCoord;\n"

"}\n";

 

QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);

QString fsrc =

"#ifdef GL_ES\n"

"#ifdef GL_FRAGMENT_PRECISION_HIGH\n"

"precision highp float;\n"

"precision highp sampler2D;\n"

"#else\n"

"precision mediump float;\n"

"precision mediump sampler2D;\n"

"#endif\n"

"#endif\n"

"in vec2 texc;\n"

"out vec4 fragColor;\n"

"uniform sampler2D tex;\n"

"void main(void)\n"

"{\n"

" fragColor = texture(tex, texc);\n"

"}\n";

Original Attachment has been moved to: GLWidget.cpp.zip

Original Attachment has been moved to: Window.cpp.zip

Labels (1)
0 Kudos
3 Replies

815 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hi Hartmut,

I tested on MX6Q not MX6QT and latest BSP, frankly I did not see any issue with your code. however your VBOs create buffer objects in memory and allow the GPU to directly access memory without CPU intervention (DMA). The memory manager can optimize buffer placement using feedback from the application. I suggest  to implement dynamic VBO depending on your preference, but one recommendation is to allocate a 2 MB dynamic VBO block and upload data to using different offsets for each dynamic buffer.

 

Hope this helps

0 Kudos

815 Views
hartmutbehrensf
Contributor I

Dear Bio_TICFSL,

I made a small program to recreate the problem. It is attached - in source, and compiled form, ready to run on iMX6.

Also attached is screenshot of graphical corruption seen on iMX6 SABRESDB board (IMG_20170623_140751.jpg)) as well as a screenshot when program is working correctly.

To see the problem, run ./textures, then click on the first rotating red cube. It should change into a smaller, faster rotating blue cube (as shown in Screenshot from 2017-06-23.png), but instead graphical corruption appears. 

0 Kudos

815 Views
hartmutbehrensf
Contributor I

So I found that the situations is improved *a bit* if you include at least one more element in the struct, i.e.: 

"struct VertexData {\n"

" mat4 rotMatrix;\n"

" vec4 dummy;\n" //the iMX6 needs at least two struct members, otherwise graphical corruption

"};\n"

Using this setup, vData[0] contains the expected matrix. 

However, vData[1] and all following elements are still corrupted.

0 Kudos