commit 2b7d2abb7bfa4fd427d80e18e5c932f171d979fb
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Jan 13 13:21:41 2021 +0100

    Remove UBO from the fragment shader and come back to the default of only 5 concurrent fragment effects. All because UBOs in fragment shader crash on Adreno 510 and Adreno 506.

diff --git a/src/main/java/org/distorted/library/effect/EffectType.java b/src/main/java/org/distorted/library/effect/EffectType.java
index c7b4fea..2341437 100644
--- a/src/main/java/org/distorted/library/effect/EffectType.java
+++ b/src/main/java/org/distorted/library/effect/EffectType.java
@@ -75,7 +75,7 @@ public enum EffectType
                        // EffectQueueMatrix at any given time. This can be changed with a call
                        // to EffectQueueMatrix.setMax(int)
     maxtable[1] =100;  // Max 100 VERTEX Effects
-    maxtable[2] =100;  // Max 100 FRAGMENT Effects
+    maxtable[2] =  5;  // Max 5 FRAGMENT Effects
     maxtable[3] =  3;  // Max 3 POSTPROCESSING Effects
     }
 
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
index dd2a679..ef3466d 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
@@ -43,8 +43,6 @@ public abstract class EffectQueue implements InternalMaster.Slave
 
   static final int VERT_INT_UBO_BINDING = 5;
   static final int VERT_FLO_UBO_BINDING = 6;
-  static final int FRAG_INT_UBO_BINDING = 7;
-  static final int FRAG_FLO_UBO_BINDING = 8;
 
   private static final int CREATE = 0;
   private static final int ATTACH = 1;
@@ -67,7 +65,7 @@ public abstract class EffectQueue implements InternalMaster.Slave
     {
     int type;
     int num1, num2;
-    boolean notify;
+    boolean bool;
     Effect effect;
 
     Job(int t, int m1, int m2, boolean n, Effect e)
@@ -75,7 +73,7 @@ public abstract class EffectQueue implements InternalMaster.Slave
       type  = t;
       num1  = m1;
       num2  = m2;
-      notify= n;
+      bool  = n;
       effect= e;
       }
     }
@@ -84,7 +82,7 @@ public abstract class EffectQueue implements InternalMaster.Slave
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
-  EffectQueue(int numFloatUniforms, int numIntUniforms, int index)
+  EffectQueue(int numFloatUniforms, int numIntUniforms, boolean useUBO, int index)
     {
     mCreated        = false;
     mTime           = 0;
@@ -95,7 +93,7 @@ public abstract class EffectQueue implements InternalMaster.Slave
 
     mJobs = new ArrayList<>();
 
-    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number
+    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms,useUBO,null)); // create the stuff that depends on max number
     InternalMaster.newSlave(this);                                          // of uniforms later, on first render.
     }
 
@@ -442,8 +440,8 @@ public abstract class EffectQueue implements InternalMaster.Slave
                      if( max>0 )
                        {
                        mEffects= new Effect[max];
-                       mUBF    = new UniformBlockFloatUniforms(job.num1, max);
-                       mUBI    = new UniformBlockIntUniforms  (job.num2, max);
+                       mUBF    = new UniformBlockFloatUniforms(job.num1, max, job.bool);
+                       mUBI    = new UniformBlockIntUniforms  (job.num2, max, job.bool);
                        }
                      mCreated = true;
 
@@ -488,6 +486,13 @@ public abstract class EffectQueue implements InternalMaster.Slave
                        mEffects[j] = null;
                        }
 
+                     // TODO: notify listeners?
+                     /* if( job.bool )
+                          {
+                          // ...
+                          }
+                      */
+
                      mNumEffects= 0;
                      break;
         }
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java b/src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java
index a2204b5..85f5518 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java
@@ -31,18 +31,18 @@ class EffectQueueFragment extends EffectQueue
   {
   private static final int NUM_FLOAT_UNIFORMS = FragmentEffect.NUM_FLOAT_UNIFORMS;
   private static final int NUM_INT_UNIFORMS   = FragmentEffect.NUM_INT_UNIFORMS;
-
+  private static final boolean USE_UBO        = false;
   private static final int INDEX = EffectType.FRAGMENT.ordinal();
 
   private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
-  private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
-  private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
+  private final static int[] mIntUniformsH = new int[MAIN_VARIANTS];
+  private final static int[] mFloUniformsH = new int[MAIN_VARIANTS];
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
   EffectQueueFragment()
     { 
-    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
+    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -57,8 +57,8 @@ class EffectQueueFragment extends EffectQueue
   static void uniforms(int mProgramH, int variant)
     {
     mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "fNumEffects");
-    mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformProperties");
-    mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformFloats");
+    mIntUniformsH[variant]  = GLES30.glGetUniformLocation  ( mProgramH, "fProperties");
+    mFloUniformsH[variant]  = GLES30.glGetUniformLocation  ( mProgramH, "fUniforms");
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -80,8 +80,6 @@ class EffectQueueFragment extends EffectQueue
           EffectMessageSender.newMessage(mEffects[i]);
           }
         }
-
-      mUBF.invalidate();
       }
 
     mTime = currTime;  
@@ -95,11 +93,11 @@ class EffectQueueFragment extends EffectQueue
 
     if( mNumEffects>0 )
       {
-      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_INT_UBO_BINDING, mUBI.getIndex());
-      GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], FRAG_INT_UBO_BINDING);
+      int[]   arrayI = mUBI.getBackingArray();
+      float[] arrayF = mUBF.getBackingArray();
 
-      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_FLO_UBO_BINDING, mUBF.getIndex());
-      GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], FRAG_FLO_UBO_BINDING);
+      GLES30.glUniform4iv( mIntUniformsH[variant],                       mNumEffects, arrayI, 0);
+      GLES30.glUniform4fv( mFloUniformsH[variant],(NUM_FLOAT_UNIFORMS/4)*mNumEffects, arrayF, 0);
       }  
     }
   }
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java b/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
index 6d01a36..47af267 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
@@ -32,7 +32,7 @@ class EffectQueueMatrix extends EffectQueue
   {
   private static final int NUM_FLOAT_UNIFORMS = MatrixEffect.NUM_FLOAT_UNIFORMS;
   private static final int NUM_INT_UNIFORMS   = MatrixEffect.NUM_INT_UNIFORMS;
-
+  private static final boolean USE_UBO        = false;
   private static final int INDEX = EffectType.MATRIX.ordinal();
 
   private static final float[] mMVPMatrix       = new float[16];
@@ -47,7 +47,7 @@ class EffectQueueMatrix extends EffectQueue
    
   EffectQueueMatrix()
     { 
-    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
+    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java b/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
index 5b0d528..3cbe2be 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
@@ -49,7 +49,7 @@ public class EffectQueuePostprocess extends EffectQueue
   {
   private static final int NUM_FLOAT_UNIFORMS = PostprocessEffect.NUM_FLOAT_UNIFORMS;
   private static final int NUM_INT_UNIFORMS   = PostprocessEffect.NUM_INT_UNIFORMS;
-
+  private static final boolean USE_UBO        = false;
   private static final int INDEX = EffectType.POSTPROCESS.ordinal();
 
   private int mHalo;
@@ -64,7 +64,7 @@ public class EffectQueuePostprocess extends EffectQueue
 
   EffectQueuePostprocess()
     { 
-    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX );
+    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX );
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java b/src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java
index 1335957..a63ab55 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java
@@ -35,6 +35,7 @@ public class EffectQueueVertex extends EffectQueue
   {
   private static final int NUM_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS;
   private static final int NUM_INT_UNIFORMS   = VertexEffect.NUM_INT_UNIFORMS;
+  private static final boolean USE_UBO        = true;
 
   private static final int INDEX = EffectType.VERTEX.ordinal();
 
@@ -47,7 +48,7 @@ public class EffectQueueVertex extends EffectQueue
    
   public EffectQueueVertex()
     { 
-    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
+    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java b/src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java
index c6f0cc6..0df066d 100644
--- a/src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java
+++ b/src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java
@@ -32,18 +32,24 @@ import org.distorted.library.main.InternalBuffer;
  */
 public class UniformBlockFloatUniforms
   {
-  private final InternalBuffer mUBO;
+  private InternalBuffer mUBO;
   private final float[] mArray;
   private final int mNumUniforms, mSize;
+  private final boolean mReallyUseUBO;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public UniformBlockFloatUniforms(int numUniforms, int size)
+  public UniformBlockFloatUniforms(int numUniforms, int size, boolean reallyUse)
     {
     mNumUniforms = numUniforms;
     mSize        = size;
     mArray= new float[mNumUniforms*mSize];
-    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+    mReallyUseUBO= reallyUse;
+
+    if( mReallyUseUBO )
+      {
+      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -53,8 +59,14 @@ public class UniformBlockFloatUniforms
     mNumUniforms = original.mNumUniforms;
     mSize        = original.mSize;
     mArray= new float[mNumUniforms*mSize];
+    mReallyUseUBO= original.mReallyUseUBO;
+
     System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize);
-    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+
+    if( mReallyUseUBO )
+      {
+      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -69,21 +81,31 @@ public class UniformBlockFloatUniforms
   public void remove(int pos, int numEffects)
     {
     System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
-    mUBO.invalidate();
+
+    if( mReallyUseUBO )
+      {
+      mUBO.invalidate();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void markForDeletion()
     {
-    mUBO.markForDeletion();
+    if( mReallyUseUBO )
+      {
+      mUBO.markForDeletion();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void invalidate()
     {
-    mUBO.invalidate();
+    if( mReallyUseUBO )
+      {
+      mUBO.invalidate();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -99,7 +121,7 @@ public class UniformBlockFloatUniforms
     {
     StringBuilder builder = new StringBuilder();
 
-    builder.append(mUBO.getID());
+    builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
     builder.append(':');
 
     for(int i=0; i<6; i++)
diff --git a/src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java b/src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java
index 067aa92..8f236df 100644
--- a/src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java
+++ b/src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java
@@ -32,18 +32,24 @@ import org.distorted.library.main.InternalBuffer;
  */
 public class UniformBlockIntUniforms
   {
-  private final InternalBuffer mUBO;
+  private InternalBuffer mUBO;
   private final int[] mArray;
   private final int mNumUniforms, mSize;
+  private final boolean mReallyUseUBO;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public UniformBlockIntUniforms(int numUniforms, int size)
+  public UniformBlockIntUniforms(int numUniforms, int size, boolean reallyUse)
     {
     mNumUniforms = numUniforms;
     mSize        = size;
     mArray= new int[mNumUniforms*mSize];
-    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+    mReallyUseUBO= reallyUse;
+
+    if( mReallyUseUBO )
+      {
+      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -53,8 +59,14 @@ public class UniformBlockIntUniforms
     mNumUniforms = original.mNumUniforms;
     mSize        = original.mSize;
     mArray= new int[mNumUniforms*mSize];
+    mReallyUseUBO= original.mReallyUseUBO;
+
     System.arraycopy(original.mArray, 0, mArray, 0, mSize);
-    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+
+    if( mReallyUseUBO )
+      {
+      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -69,7 +81,11 @@ public class UniformBlockIntUniforms
   public void remove(int pos, int numEffects)
     {
     System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
-    mUBO.invalidate();
+
+    if( mReallyUseUBO )
+      {
+      mUBO.invalidate();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -77,7 +93,11 @@ public class UniformBlockIntUniforms
   public void makeHole(int pos, int numEffects)
     {
     System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) );
-    mUBO.invalidate();
+
+    if( mReallyUseUBO )
+      {
+      mUBO.invalidate();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -85,7 +105,11 @@ public class UniformBlockIntUniforms
   public void addOrdinal(int pos, int ordinal)
     {
     mArray[mNumUniforms*pos] = ordinal;
-    mUBO.invalidate();
+
+    if( mReallyUseUBO )
+      {
+      mUBO.invalidate();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -93,14 +117,28 @@ public class UniformBlockIntUniforms
   public void addAssociations(int pos, Effect effect)
     {
     effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3);
-    mUBO.invalidate();
+
+    if( mReallyUseUBO )
+      {
+      mUBO.invalidate();
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void markForDeletion()
     {
-    mUBO.markForDeletion();
+    if( mReallyUseUBO )
+      {
+      mUBO.markForDeletion();
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int[] getBackingArray()
+    {
+    return mArray;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -109,7 +147,7 @@ public class UniformBlockIntUniforms
     {
     StringBuilder builder = new StringBuilder();
 
-    builder.append(mUBO.getID());
+    builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
     builder.append(':');
 
     for(int i=0; i<6; i++)
diff --git a/src/main/res/raw/main_fragment_shader.glsl b/src/main/res/raw/main_fragment_shader.glsl
index 50c7535..62e1a98 100644
--- a/src/main/res/raw/main_fragment_shader.glsl
+++ b/src/main/res/raw/main_fragment_shader.glsl
@@ -47,18 +47,12 @@ layout (std430,binding=1) buffer linkedlist  // first (u_Size.x*u_Size.y) uints
 #if NUM_FRAGMENT>0
 uniform int fNumEffects;                     // total number of fragment effects
 
-layout (std140) uniform fUniformProperties
-  {
-  ivec4 fProperties[NUM_FRAGMENT];           // their properties, 4 ints:
+uniform ivec4 fProperties[NUM_FRAGMENT];     // their properties, 4 ints:
                                              // name of the effect, unused, unused, unused
-  };
 
-layout (std140) uniform fUniformFloats
-  {
-  vec4 fUniforms[3*NUM_FRAGMENT];            // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
+uniform vec4 fUniforms[3*NUM_FRAGMENT];      // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
                                              // The first vec4 is the Interpolated values,
                                              // second vec4: first float - cache, next 3: Center, the third - the Region.
-  };
 
 #endif    // NUM_FRAGMENT>0
 
