Project

General

Profile

« Previous | Next » 

Revision 2b7d2abb

Added by Leszek Koltunski almost 4 years ago

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.

View differences:

src/main/java/org/distorted/library/effect/EffectType.java
75 75
                       // EffectQueueMatrix at any given time. This can be changed with a call
76 76
                       // to EffectQueueMatrix.setMax(int)
77 77
    maxtable[1] =100;  // Max 100 VERTEX Effects
78
    maxtable[2] =100;  // Max 100 FRAGMENT Effects
78
    maxtable[2] =  5;  // Max 5 FRAGMENT Effects
79 79
    maxtable[3] =  3;  // Max 3 POSTPROCESSING Effects
80 80
    }
81 81

  
src/main/java/org/distorted/library/effectqueue/EffectQueue.java
43 43

  
44 44
  static final int VERT_INT_UBO_BINDING = 5;
45 45
  static final int VERT_FLO_UBO_BINDING = 6;
46
  static final int FRAG_INT_UBO_BINDING = 7;
47
  static final int FRAG_FLO_UBO_BINDING = 8;
48 46

  
49 47
  private static final int CREATE = 0;
50 48
  private static final int ATTACH = 1;
......
67 65
    {
68 66
    int type;
69 67
    int num1, num2;
70
    boolean notify;
68
    boolean bool;
71 69
    Effect effect;
72 70

  
73 71
    Job(int t, int m1, int m2, boolean n, Effect e)
......
75 73
      type  = t;
76 74
      num1  = m1;
77 75
      num2  = m2;
78
      notify= n;
76
      bool  = n;
79 77
      effect= e;
80 78
      }
81 79
    }
......
84 82

  
85 83
///////////////////////////////////////////////////////////////////////////////////////////////////
86 84
   
87
  EffectQueue(int numFloatUniforms, int numIntUniforms, int index)
85
  EffectQueue(int numFloatUniforms, int numIntUniforms, boolean useUBO, int index)
88 86
    {
89 87
    mCreated        = false;
90 88
    mTime           = 0;
......
95 93

  
96 94
    mJobs = new ArrayList<>();
97 95

  
98
    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number
96
    mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms,useUBO,null)); // create the stuff that depends on max number
99 97
    InternalMaster.newSlave(this);                                          // of uniforms later, on first render.
100 98
    }
101 99

  
......
442 440
                     if( max>0 )
443 441
                       {
444 442
                       mEffects= new Effect[max];
445
                       mUBF    = new UniformBlockFloatUniforms(job.num1, max);
446
                       mUBI    = new UniformBlockIntUniforms  (job.num2, max);
443
                       mUBF    = new UniformBlockFloatUniforms(job.num1, max, job.bool);
444
                       mUBI    = new UniformBlockIntUniforms  (job.num2, max, job.bool);
447 445
                       }
448 446
                     mCreated = true;
449 447

  
......
488 486
                       mEffects[j] = null;
489 487
                       }
490 488

  
489
                     // TODO: notify listeners?
490
                     /* if( job.bool )
491
                          {
492
                          // ...
493
                          }
494
                      */
495

  
491 496
                     mNumEffects= 0;
492 497
                     break;
493 498
        }
src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java
31 31
  {
32 32
  private static final int NUM_FLOAT_UNIFORMS = FragmentEffect.NUM_FLOAT_UNIFORMS;
33 33
  private static final int NUM_INT_UNIFORMS   = FragmentEffect.NUM_INT_UNIFORMS;
34

  
34
  private static final boolean USE_UBO        = false;
35 35
  private static final int INDEX = EffectType.FRAGMENT.ordinal();
36 36

  
37 37
  private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
38
  private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
39
  private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
38
  private final static int[] mIntUniformsH = new int[MAIN_VARIANTS];
39
  private final static int[] mFloUniformsH = new int[MAIN_VARIANTS];
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
42 42
   
43 43
  EffectQueueFragment()
44 44
    { 
45
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
45
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
46 46
    }
47 47

  
48 48
///////////////////////////////////////////////////////////////////////////////////////////////////
......
57 57
  static void uniforms(int mProgramH, int variant)
58 58
    {
59 59
    mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "fNumEffects");
60
    mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformProperties");
61
    mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformFloats");
60
    mIntUniformsH[variant]  = GLES30.glGetUniformLocation  ( mProgramH, "fProperties");
61
    mFloUniformsH[variant]  = GLES30.glGetUniformLocation  ( mProgramH, "fUniforms");
62 62
    }
63 63

  
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
......
80 80
          EffectMessageSender.newMessage(mEffects[i]);
81 81
          }
82 82
        }
83

  
84
      mUBF.invalidate();
85 83
      }
86 84

  
87 85
    mTime = currTime;  
......
95 93

  
96 94
    if( mNumEffects>0 )
97 95
      {
98
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_INT_UBO_BINDING, mUBI.getIndex());
99
      GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], FRAG_INT_UBO_BINDING);
96
      int[]   arrayI = mUBI.getBackingArray();
97
      float[] arrayF = mUBF.getBackingArray();
100 98

  
101
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_FLO_UBO_BINDING, mUBF.getIndex());
102
      GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], FRAG_FLO_UBO_BINDING);
99
      GLES30.glUniform4iv( mIntUniformsH[variant],                       mNumEffects, arrayI, 0);
100
      GLES30.glUniform4fv( mFloUniformsH[variant],(NUM_FLOAT_UNIFORMS/4)*mNumEffects, arrayF, 0);
103 101
      }  
104 102
    }
105 103
  }
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
32 32
  {
33 33
  private static final int NUM_FLOAT_UNIFORMS = MatrixEffect.NUM_FLOAT_UNIFORMS;
34 34
  private static final int NUM_INT_UNIFORMS   = MatrixEffect.NUM_INT_UNIFORMS;
35

  
35
  private static final boolean USE_UBO        = false;
36 36
  private static final int INDEX = EffectType.MATRIX.ordinal();
37 37

  
38 38
  private static final float[] mMVPMatrix       = new float[16];
......
47 47
   
48 48
  EffectQueueMatrix()
49 49
    { 
50
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
50
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
51 51
    }
52 52

  
53 53
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
49 49
  {
50 50
  private static final int NUM_FLOAT_UNIFORMS = PostprocessEffect.NUM_FLOAT_UNIFORMS;
51 51
  private static final int NUM_INT_UNIFORMS   = PostprocessEffect.NUM_INT_UNIFORMS;
52

  
52
  private static final boolean USE_UBO        = false;
53 53
  private static final int INDEX = EffectType.POSTPROCESS.ordinal();
54 54

  
55 55
  private int mHalo;
......
64 64

  
65 65
  EffectQueuePostprocess()
66 66
    { 
67
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX );
67
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX );
68 68
    }
69 69

  
70 70
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java
35 35
  {
36 36
  private static final int NUM_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS;
37 37
  private static final int NUM_INT_UNIFORMS   = VertexEffect.NUM_INT_UNIFORMS;
38
  private static final boolean USE_UBO        = true;
38 39

  
39 40
  private static final int INDEX = EffectType.VERTEX.ordinal();
40 41

  
......
47 48
   
48 49
  public EffectQueueVertex()
49 50
    { 
50
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
51
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
51 52
    }
52 53

  
53 54
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java
32 32
 */
33 33
public class UniformBlockFloatUniforms
34 34
  {
35
  private final InternalBuffer mUBO;
35
  private InternalBuffer mUBO;
36 36
  private final float[] mArray;
37 37
  private final int mNumUniforms, mSize;
38
  private final boolean mReallyUseUBO;
38 39

  
39 40
///////////////////////////////////////////////////////////////////////////////////////////////////
40 41

  
41
  public UniformBlockFloatUniforms(int numUniforms, int size)
42
  public UniformBlockFloatUniforms(int numUniforms, int size, boolean reallyUse)
42 43
    {
43 44
    mNumUniforms = numUniforms;
44 45
    mSize        = size;
45 46
    mArray= new float[mNumUniforms*mSize];
46
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
47
    mReallyUseUBO= reallyUse;
48

  
49
    if( mReallyUseUBO )
50
      {
51
      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
52
      }
47 53
    }
48 54

  
49 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
53 59
    mNumUniforms = original.mNumUniforms;
54 60
    mSize        = original.mSize;
55 61
    mArray= new float[mNumUniforms*mSize];
62
    mReallyUseUBO= original.mReallyUseUBO;
63

  
56 64
    System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize);
57
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
65

  
66
    if( mReallyUseUBO )
67
      {
68
      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
69
      }
58 70
    }
59 71

  
60 72
///////////////////////////////////////////////////////////////////////////////////////////////////
......
69 81
  public void remove(int pos, int numEffects)
70 82
    {
71 83
    System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
72
    mUBO.invalidate();
84

  
85
    if( mReallyUseUBO )
86
      {
87
      mUBO.invalidate();
88
      }
73 89
    }
74 90

  
75 91
///////////////////////////////////////////////////////////////////////////////////////////////////
76 92

  
77 93
  public void markForDeletion()
78 94
    {
79
    mUBO.markForDeletion();
95
    if( mReallyUseUBO )
96
      {
97
      mUBO.markForDeletion();
98
      }
80 99
    }
81 100

  
82 101
///////////////////////////////////////////////////////////////////////////////////////////////////
83 102

  
84 103
  public void invalidate()
85 104
    {
86
    mUBO.invalidate();
105
    if( mReallyUseUBO )
106
      {
107
      mUBO.invalidate();
108
      }
87 109
    }
88 110

  
89 111
///////////////////////////////////////////////////////////////////////////////////////////////////
......
99 121
    {
100 122
    StringBuilder builder = new StringBuilder();
101 123

  
102
    builder.append(mUBO.getID());
124
    builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
103 125
    builder.append(':');
104 126

  
105 127
    for(int i=0; i<6; i++)
src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java
32 32
 */
33 33
public class UniformBlockIntUniforms
34 34
  {
35
  private final InternalBuffer mUBO;
35
  private InternalBuffer mUBO;
36 36
  private final int[] mArray;
37 37
  private final int mNumUniforms, mSize;
38
  private final boolean mReallyUseUBO;
38 39

  
39 40
///////////////////////////////////////////////////////////////////////////////////////////////////
40 41

  
41
  public UniformBlockIntUniforms(int numUniforms, int size)
42
  public UniformBlockIntUniforms(int numUniforms, int size, boolean reallyUse)
42 43
    {
43 44
    mNumUniforms = numUniforms;
44 45
    mSize        = size;
45 46
    mArray= new int[mNumUniforms*mSize];
46
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
47
    mReallyUseUBO= reallyUse;
48

  
49
    if( mReallyUseUBO )
50
      {
51
      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
52
      }
47 53
    }
48 54

  
49 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
53 59
    mNumUniforms = original.mNumUniforms;
54 60
    mSize        = original.mSize;
55 61
    mArray= new int[mNumUniforms*mSize];
62
    mReallyUseUBO= original.mReallyUseUBO;
63

  
56 64
    System.arraycopy(original.mArray, 0, mArray, 0, mSize);
57
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
65

  
66
    if( mReallyUseUBO )
67
      {
68
      mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
69
      }
58 70
    }
59 71

  
60 72
///////////////////////////////////////////////////////////////////////////////////////////////////
......
69 81
  public void remove(int pos, int numEffects)
70 82
    {
71 83
    System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
72
    mUBO.invalidate();
84

  
85
    if( mReallyUseUBO )
86
      {
87
      mUBO.invalidate();
88
      }
73 89
    }
74 90

  
75 91
///////////////////////////////////////////////////////////////////////////////////////////////////
......
77 93
  public void makeHole(int pos, int numEffects)
78 94
    {
79 95
    System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) );
80
    mUBO.invalidate();
96

  
97
    if( mReallyUseUBO )
98
      {
99
      mUBO.invalidate();
100
      }
81 101
    }
82 102

  
83 103
///////////////////////////////////////////////////////////////////////////////////////////////////
......
85 105
  public void addOrdinal(int pos, int ordinal)
86 106
    {
87 107
    mArray[mNumUniforms*pos] = ordinal;
88
    mUBO.invalidate();
108

  
109
    if( mReallyUseUBO )
110
      {
111
      mUBO.invalidate();
112
      }
89 113
    }
90 114

  
91 115
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 117
  public void addAssociations(int pos, Effect effect)
94 118
    {
95 119
    effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3);
96
    mUBO.invalidate();
120

  
121
    if( mReallyUseUBO )
122
      {
123
      mUBO.invalidate();
124
      }
97 125
    }
98 126

  
99 127
///////////////////////////////////////////////////////////////////////////////////////////////////
100 128

  
101 129
  public void markForDeletion()
102 130
    {
103
    mUBO.markForDeletion();
131
    if( mReallyUseUBO )
132
      {
133
      mUBO.markForDeletion();
134
      }
135
    }
136

  
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

  
139
  public int[] getBackingArray()
140
    {
141
    return mArray;
104 142
    }
105 143

  
106 144
///////////////////////////////////////////////////////////////////////////////////////////////////
......
109 147
    {
110 148
    StringBuilder builder = new StringBuilder();
111 149

  
112
    builder.append(mUBO.getID());
150
    builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
113 151
    builder.append(':');
114 152

  
115 153
    for(int i=0; i<6; i++)
src/main/res/raw/main_fragment_shader.glsl
47 47
#if NUM_FRAGMENT>0
48 48
uniform int fNumEffects;                     // total number of fragment effects
49 49

  
50
layout (std140) uniform fUniformProperties
51
  {
52
  ivec4 fProperties[NUM_FRAGMENT];           // their properties, 4 ints:
50
uniform ivec4 fProperties[NUM_FRAGMENT];     // their properties, 4 ints:
53 51
                                             // name of the effect, unused, unused, unused
54
  };
55 52

  
56
layout (std140) uniform fUniformFloats
57
  {
58
  vec4 fUniforms[3*NUM_FRAGMENT];            // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
53
uniform vec4 fUniforms[3*NUM_FRAGMENT];      // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2].
59 54
                                             // The first vec4 is the Interpolated values,
60 55
                                             // second vec4: first float - cache, next 3: Center, the third - the Region.
61
  };
62 56

  
63 57
#endif    // NUM_FRAGMENT>0
64 58

  

Also available in: Unified diff