commit 29b5cd0df767d71341aa57b7bea1828261da8570
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Jun 1 21:19:25 2018 +0100

    New self-contained (i.e. not dependant on the library) App to check bugs on Mali GPU.

diff --git a/src/main/java/org/distorted/examples/mali/MaliActivity.java b/src/main/java/org/distorted/examples/mali/MaliActivity.java
new file mode 100644
index 0000000..5ad5a3d
--- /dev/null
+++ b/src/main/java/org/distorted/examples/mali/MaliActivity.java
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.mali;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class MaliActivity extends Activity
+{
+    private MaliSurfaceView mView;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onCreate(Bundle savedState) 
+      {
+      super.onCreate(savedState);
+      mView = new MaliSurfaceView(this);
+      setContentView(mView);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onPause() 
+      {
+      mView.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onResume() 
+      {
+      super.onResume();
+      mView.onResume();
+      }
+}
diff --git a/src/main/java/org/distorted/examples/mali/MaliRenderer.java b/src/main/java/org/distorted/examples/mali/MaliRenderer.java
new file mode 100644
index 0000000..e066fa5
--- /dev/null
+++ b/src/main/java/org/distorted/examples/mali/MaliRenderer.java
@@ -0,0 +1,190 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.mali;
+
+import android.opengl.GLES31;
+import android.opengl.GLSurfaceView;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class MaliRenderer implements GLSurfaceView.Renderer
+{
+    private int mWidth, mHeight;
+
+    private static int[] mSSBO = new int[1];
+    private static int mProgramHandle,mSizeH,mPosH;
+    private static final FloatBuffer mQuadPositions;
+
+    static
+      {
+      mSSBO[0] = -1;
+
+      float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
+      mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
+      mQuadPositions.put(positionData).position(0);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    MaliRenderer(GLSurfaceView v)
+      {
+
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onDrawFrame(GL10 glUnused) 
+      {
+      GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
+      GLES31.glUseProgram(mProgramHandle);
+      GLES31.glEnableVertexAttribArray(mPosH);
+      GLES31.glViewport(0, 0, mWidth, mHeight );
+      GLES31.glUniform2ui(mSizeH, mWidth, mHeight);
+      GLES31.glVertexAttribPointer(mPosH, 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
+      GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
+      {
+      final String vertSource =
+
+      "#version 310 es                                      \n" +
+      "precision highp float;                               \n" +
+      "precision highp int;                                 \n" +
+      "in vec2 a_Position;                                  \n" +
+      "out vec2 v_Pixel;                                    \n" +
+      "uniform uvec2 u_Size;                                \n" +
+
+      "void main()                                          \n" +
+      "{                                                    \n" +
+      "v_Pixel         = (a_Position + 0.5) * vec2(u_Size); \n" +
+      "gl_Position     = vec4(2.0*a_Position,1.0,1.0);      \n" +
+      "} ";
+
+      final String fragSource =
+
+      "#version 310 es                                      \n" +
+      "precision highp float;                               \n" +
+      "precision highp int;                                 \n" +
+      "out vec4 fragColor;                                  \n" +
+      "in vec2 v_Pixel;                                     \n" +
+      "uniform uvec2 u_Size;                                \n" +
+
+      "layout (std430,binding=1) buffer linkedlist          \n" +
+      " {                                                   \n" +
+      " uint u_Records[];                                   \n" +
+      " };                                                  \n" +
+
+      "void main()                                                 \n" +
+      " {                                                          \n" +
+      " uint index= uint(v_Pixel.x) + uint(v_Pixel.y) * u_Size.x;  \n" +
+      " uint sum = 0u;                                             \n" +
+
+      " if( index>=1u )                                            \n" +
+      "   {                                                        \n" +
+      "   //for(uint i=index; i>=index-1u; i--) sum += u_Records[i]; \n" +
+      "   sum += u_Records[index];                               \n" +
+      "   sum += u_Records[index-1u];                            \n" +
+      "   }                                                        \n" +
+
+      " u_Records[index] = sum;                                    \n" +
+
+      " fragColor = vec4(0.0,1.0,0.0,1.0);                         \n" +
+      " }";
+
+      int vertHandle = GLES31.glCreateShader(GLES31.GL_VERTEX_SHADER);
+      GLES31.glShaderSource(vertHandle, vertSource);
+      GLES31.glCompileShader(vertHandle);
+
+      final int[] compileStatus = new int[1];
+      GLES31.glGetShaderiv(vertHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0);
+
+      if (compileStatus[0] != GLES31.GL_TRUE)
+        {
+        String error = GLES31.glGetShaderInfoLog(vertHandle);
+        android.util.Log.e("Program", "error compiling vert :" + error);
+        GLES31.glDeleteShader(vertHandle);
+        }
+
+      int fragHandle = GLES31.glCreateShader(GLES31.GL_FRAGMENT_SHADER);
+      GLES31.glShaderSource(fragHandle, fragSource);
+      GLES31.glCompileShader(fragHandle);
+
+      GLES31.glGetShaderiv(fragHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0);
+
+      if (compileStatus[0] != GLES31.GL_TRUE)
+        {
+        String error = GLES31.glGetShaderInfoLog(fragHandle);
+        android.util.Log.e("Program", "error compiling frag :" + error);
+        GLES31.glDeleteShader(fragHandle);
+        }
+
+      mProgramHandle = GLES31.glCreateProgram();
+
+      if (mProgramHandle != 0)
+        {
+        GLES31.glAttachShader(mProgramHandle, vertHandle);
+        GLES31.glAttachShader(mProgramHandle, fragHandle);
+
+        GLES31.glBindAttribLocation(mProgramHandle, 0, "a_Position");
+
+        GLES31.glLinkProgram(mProgramHandle);
+
+        final int[] linkStatus = new int[1];
+        GLES31.glGetProgramiv(mProgramHandle, GLES31.GL_LINK_STATUS, linkStatus, 0);
+
+        if (linkStatus[0] != GLES31.GL_TRUE)
+          {
+          String error = GLES31.glGetProgramInfoLog(mProgramHandle);
+          GLES31.glDeleteProgram(mProgramHandle);
+          android.util.Log.e("Program", "error linking :" + error);
+          }
+        }
+
+      mPosH = GLES31.glGetAttribLocation ( mProgramHandle, "a_Position");
+      mSizeH= GLES31.glGetUniformLocation( mProgramHandle, "u_Size");
+
+      if( mSSBO[0]<0 )
+        {
+        GLES31.glGenBuffers(1,mSSBO,0);
+        GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]);
+        GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, (1<<23) , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
+        GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mSSBO[0]);
+        GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onSurfaceChanged(GL10 glUnused, int width, int height)
+      {
+      mWidth = width;
+      mHeight= height;
+      }
+}
diff --git a/src/main/java/org/distorted/examples/mali/MaliSurfaceView.java b/src/main/java/org/distorted/examples/mali/MaliSurfaceView.java
new file mode 100644
index 0000000..6a25f42
--- /dev/null
+++ b/src/main/java/org/distorted/examples/mali/MaliSurfaceView.java
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.examples.mali;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class MaliSurfaceView extends GLSurfaceView
+{
+
+    public MaliSurfaceView(Context context)
+      {
+      super(context);
+      setEGLContextClientVersion(3);
+      setRenderer(new MaliRenderer(this));
+      }
+}
+
