Project

General

Profile

« Previous | Next » 

Revision 5f35f1cb

Added by Leszek Koltunski almost 4 years ago

Only insert the 'Mali r12' FBO queue fix if we actually are running on a Mali GPU with driver version <22. (then FBOQueue=4 - unless we manually overide this down to 1 - else, always 1)

View differences:

src/main/java/org/distorted/library/main/DistortedFramebuffer.java
37 37

  
38 38
  void create()
39 39
    {
40
    if( mNumFBOs==DistortedLibrary.WAIT_FOR_FBO_QUEUE_SIZE )
41
      {
42
      // only now we know how many FBOs there should be
43
      mNumFBOs = DistortedLibrary.getQueueSize();
44
      allocateColor();
45
      allocateStuffDependantOnNumFBOS();
46
      }
47

  
40 48
    //////////////////////////////////////////////////////////////
41 49
    // COLOR
42 50

  
src/main/java/org/distorted/library/main/DistortedLibrary.java
47 47
import java.nio.ByteOrder;
48 48
import java.nio.FloatBuffer;
49 49
import java.nio.IntBuffer;
50
import java.util.regex.Matcher;
51
import java.util.regex.Pattern;
50 52

  
51 53
///////////////////////////////////////////////////////////////////////////////////////////////////
52 54
/**
......
97 99
   */
98 100
  public static final int CLONE_CHILDREN= 0x20;
99 101

  
102
  /**
103
   * When creating a DistortedScreen (which needs to have mFBOQueueSize FBOs attached), pass this
104
   * constant for 'numOfFBOs' and the number of backing FBOs will be taken from 'mFBOQueueSize'
105
   * (the value of which is most likely unknown at the time of creation of the Screen)
106
   */
107
  public static final int WAIT_FOR_FBO_QUEUE_SIZE = -1;
100 108
  /**
101 109
   * Work around bugs in ARM Mali driver by, instead to a single FBO, rendering to a circular queue
102
   * of FBO_QUEUE_SIZE FBOs. (otherwise we sometimes get a 'full pipeline flush' and the end result
110
   * of mFBOQueueSize FBOs. (otherwise we sometimes get a 'full pipeline flush' and the end result
103 111
   * might be missing part of the Objects)
104 112
   *
105
   * This bug only exists on Mali driver r12.
113
   * This bug only exists on Mali driver r12. (or more precisely it's there in r12 but fixed in r22)
106 114
   *
107 115
   * https://community.arm.com/graphics/f/discussions/10285/opengl-es-3-1-on-mali-t880-flashes
108 116
   */
109
  static final int FBO_QUEUE_SIZE = 3;
117
  private static int mFBOQueueSize;
110 118

  
111 119
  private static boolean mInitialized=false;
112 120

  
......
150 158

  
151 159
  /// OIT SSBO BUFFER ///
152 160
  private static int[] mLinkedListSSBO = new int[1];
153
  private static int[] mAtomicCounter = new int[DistortedLibrary.FBO_QUEUE_SIZE];
161
  private static int[] mAtomicCounter;
154 162
  private static int   mCurrBuffer;
155 163

  
156 164
  static
157 165
    {
158 166
    mLinkedListSSBO[0]= -1;
159 167
    mCurrBuffer       =  0;
160

  
161
    for(int i = 0; i< DistortedLibrary.FBO_QUEUE_SIZE; i++)  mAtomicCounter[i] = -1;
162 168
    }
163 169

  
164 170
  ///////////////////////////////////////////////////////////////
......
646 652
    {
647 653
    int counter = 0;
648 654

  
649
    if( mAtomicCounter[0]<0 )
655
    if( mAtomicCounter==null )
650 656
      {
651
      GLES30.glGenBuffers(DistortedLibrary.FBO_QUEUE_SIZE,mAtomicCounter,0);
657
      mAtomicCounter = new int[mFBOQueueSize];
658

  
659
      GLES30.glGenBuffers(mFBOQueueSize,mAtomicCounter,0);
652 660

  
653
      for(int i = 0; i< DistortedLibrary.FBO_QUEUE_SIZE; i++)
661
      for(int i=0; i<mFBOQueueSize; i++)
654 662
        {
655 663
        GLES30.glBindBuffer(GLES31.GL_ATOMIC_COUNTER_BUFFER, mAtomicCounter[i]);
656 664
        GLES30.glBufferData(GLES31.GL_ATOMIC_COUNTER_BUFFER, 4, null, GLES30.GL_DYNAMIC_DRAW);
......
666 674
      counter = printPreviousBuffer();
667 675
      }
668 676

  
669
    if( ++mCurrBuffer>= DistortedLibrary.FBO_QUEUE_SIZE ) mCurrBuffer = 0;
677
    if( ++mCurrBuffer>=mFBOQueueSize ) mCurrBuffer = 0;
670 678

  
671 679
    GLES30.glBindBufferBase(GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, mAtomicCounter[mCurrBuffer]);
672 680
    zeroBuffer();
......
785 793
    mBufferSize = size;
786 794
    }
787 795

  
796
///////////////////////////////////////////////////////////////////////////////////////////////////
797

  
798
  static int getQueueSize()
799
    {
800
    return mFBOQueueSize;
801
    }
802

  
788 803
///////////////////////////////////////////////////////////////////////////////////////////////////
789 804
// ARM Mali driver r12 has problems when we keep swapping many FBOs (fixed in r22)
790 805
// PowerVR GE8100 / GE8300 compiler fails to compile OIT programs.
791 806

  
792
  private static void detectBuggyDrivers()
807
  private static void detectBuggyDriversAndSetQueueSize(int queueSize)
793 808
    {
794 809
    String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
795 810
    String version = GLES30.glGetString(GLES30.GL_VERSION);
796 811
    String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
797 812

  
798
    /*
799
    android.util.Log.e("DISTORTED", "GLSL Version "+GLES30.glGetString(GLES31.GL_SHADING_LANGUAGE_VERSION));
800
    android.util.Log.e("DISTORTED", "GL Version "  +GLES30.glGetString(GLES31.GL_VERSION));
801
    android.util.Log.e("DISTORTED", "GL Vendor "   +GLES30.glGetString(GLES31.GL_VENDOR));
802
    android.util.Log.e("DISTORTED", "GL Renderer " +GLES30.glGetString(GLES31.GL_RENDERER));
803
    */
813
    mFBOQueueSize = 1;
804 814

  
805 815
    if( vendor.contains("ARM") )
806 816
      {
807
      if( version.contains("r12") )
817
      try
808 818
        {
809
        Log.e("DISTORTED", "You are running this on a ARM Mali driver r12.\nThis is a buggy driver, please update to r22. Problems with flashing expected.");
819
        String regex = ".*r(\\d+)p\\d.*";
820
        Pattern pattern = Pattern.compile(regex);
821
        Matcher matcher = pattern.matcher(version);
822

  
823
        if( matcher.find() )
824
          {
825
          String driverVersion = matcher.group(1);
826

  
827
          if( driverVersion!=null )
828
            {
829
            int drvVersion = Integer.parseInt(driverVersion);
830

  
831
            if( drvVersion<22 )
832
              {
833
              Log.e("DISTORTED", "You are running this on a ARM Mali driver r"+driverVersion+".\n" +
834
                    "This is a buggy driver, please update to r22. Inserting workaround which uses a lot of memory.");
835

  
836
              mFBOQueueSize = queueSize;
837
              }
838
            }
839
          }
840
        }
841
      catch(Exception ex)
842
        {
843
        android.util.Log.e("library", "exception trying to pattern match version: "+ex.toString());
810 844
        }
811 845
      }
812 846
    else if( vendor.contains("Imagination") )
......
860 894
 * I.e. best called from GLSurfaceView.onCreate().
861 895
 * <p>
862 896
 * Needs to be called from a thread holding the OpenGL context.
863
 *   
897
 *
864 898
 * @param context Context of the App using the library - used to open up Resources and read Shader code.
865 899
 */
866 900
  public static void onCreate(final Context context) throws Exception
901
    {
902
    onCreate(context,4);
903
    }
904

  
905
///////////////////////////////////////////////////////////////////////////////////////////////////
906
/**
907
 * When OpenGL context gets created, call this method so that the library can initialise its internal data structures.
908
 * I.e. best called from GLSurfaceView.onCreate().
909
 * <p>
910
 * Needs to be called from a thread holding the OpenGL context.
911
 *   
912
 * @param context Context of the App using the library - used to open up Resources and read Shader code.
913
 * @param queueSize the size of the FBO queue, a workaround for the bug on Mali drivers.
914
 */
915
  public static void onCreate(final Context context, int queueSize) throws Exception
867 916
    {
868 917
    final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
869 918
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
......
888 937
    mInitialized = true;
889 938
    mOITCompilationSuccessful = false;
890 939

  
891
    detectBuggyDrivers();
940
    detectBuggyDriversAndSetQueueSize(queueSize);
892 941

  
893 942
    EffectMessageSender.startSending();
894 943

  
......
961 1010
    InternalObject.onPause();
962 1011

  
963 1012
    mLinkedListSSBO[0]= -1;
964

  
965
    for(int i = 0; i< DistortedLibrary.FBO_QUEUE_SIZE; i++) mAtomicCounter[i] = -1;
1013
    mAtomicCounter = null;
966 1014
    }
967 1015

  
968 1016
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/main/DistortedScreen.java
65 65
  private static MatrixEffectMove mMoveEffect = new MatrixEffectMove(mMoveVector);
66 66
  ///// END DEBUGGING //////////////////////////
67 67

  
68
  private int mQueueSize;
68 69
  private int mCurRenderedFBO;    // During the first FBO_QUEUE_SIZE frames, we blit the very first
69 70
  private int mToBeBlittedFBO;    // FBO one we have rendered. Then, we keep blitting the one we
70 71
  private boolean mFirstCircle;   // rendered FBO_QUEUE_SIZE ago.
......
79 80
 */
80 81
  public DistortedScreen()
81 82
    {
82
    super(DistortedLibrary.FBO_QUEUE_SIZE,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
83
    super(DistortedLibrary.WAIT_FOR_FBO_QUEUE_SIZE,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
83 84
    mDebugMode = DEBUG_MODE_NONE;
84 85
    mCurRenderedFBO = 0;
85 86
    mToBeBlittedFBO = 0;
86 87
    mFirstCircle = true;
87 88
    mDebugAllocated = false;
89
    mQueueSize = -1;
88 90
    }
89 91

  
90 92
///////////////////////////////////////////////////////////////////////////////////////////////////
......
177 179
      DistortedLibrary.drawPriv(debugEffects, debugMesh, this, time);
178 180
      }
179 181

  
180
    if( ++mCurRenderedFBO>= DistortedLibrary.FBO_QUEUE_SIZE )
182
    if( mQueueSize<=0 )
183
      {
184
      mQueueSize = DistortedLibrary.getQueueSize();
185
      }
186

  
187
    if( ++mCurRenderedFBO>=mQueueSize )
181 188
      {
182 189
      mCurRenderedFBO = 0;
183 190
      if (mFirstCircle) mFirstCircle = false;
184 191
      }
185
    if( !mFirstCircle && ++mToBeBlittedFBO>= DistortedLibrary.FBO_QUEUE_SIZE )
192
    if( !mFirstCircle && ++mToBeBlittedFBO>=mQueueSize )
186 193
      {
187 194
      mToBeBlittedFBO=0;
188 195
      }
src/main/java/org/distorted/library/main/InternalOutputSurface.java
43 43
  static final float DEFAULT_NEAR=  0.1f;
44 44

  
45 45
  private float mFOV;
46
  private int mTmpFBO;
46 47

  
47 48
  private long[] mTime;
48 49
  private float mClearR, mClearG, mClearB, mClearA, mClearDepth;
......
71 72
    mRenderWayOIT = false;
72 73
    mCurrFBO      = 0;
73 74

  
74
    mDepthStencilH = new int[numfbos];
75
    mFBOH          = new int[numfbos];
76

  
77
    mTime = new long[numfbos];
78
    for(int i=0; i<mNumFBOs;i++) mTime[i]=0;
79

  
80 75
    mRealWidth = mWidth = width;
81 76
    mRealHeight= mHeight= height;
82 77

  
......
88 83
    mDepthStencilCreated= (depthStencil== NO_DEPTH_NO_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
89 84
    mDepthStencil = depthStencil;
90 85

  
91
    mFBOH[0]         = fbo;
92
    mDepthStencilH[0]= 0;
93

  
94 86
    mClearR = 0.0f;
95 87
    mClearG = 0.0f;
96 88
    mClearB = 0.0f;
......
104 96

  
105 97
    mChildren = new InternalChildrenList(this);
106 98

  
99
    mTmpFBO = fbo;
100

  
101
    allocateStuffDependantOnNumFBOS();
107 102
    createProjection();
108 103
    }
109 104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

  
107
  void allocateStuffDependantOnNumFBOS()
108
    {
109
    if( mNumFBOs>0 )
110
      {
111
      mDepthStencilH   = new int[mNumFBOs];
112
      mDepthStencilH[0]= 0;
113

  
114
      mFBOH   = new int[mNumFBOs];
115
      mFBOH[0]= mTmpFBO;
116

  
117
      mTime = new long[mNumFBOs];
118
      for(int i=0; i<mNumFBOs;i++) mTime[i]=0;
119
      }
120
    }
121

  
110 122
///////////////////////////////////////////////////////////////////////////////////////////////////
111 123

  
112 124
  private void createProjection()
......
156 168
    final float CLEAR_D = 1.0f;
157 169
    final int   CLEAR_S = 0;
158 170

  
171
    final int queueSize = DistortedLibrary.getQueueSize();
159 172
    float mipmap=1.0f;
160 173

  
161 174
    for (int j=0; j<quality; j++) mipmap *= EffectQuality.MULTIPLIER;
162 175

  
163
    mBuffer[quality] = new DistortedFramebuffer(DistortedLibrary.FBO_QUEUE_SIZE,2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
176
    mBuffer[quality] = new DistortedFramebuffer(queueSize,2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(width*mipmap), (int)(height*mipmap) );
164 177
    mBuffer[quality].mMipmap = mipmap;
165 178
    mBuffer[quality].mNear = near;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
166 179
    mBuffer[quality].glClearColor(CLEAR_R, CLEAR_G, CLEAR_B, CLEAR_A);
......
172 185
    GLES30.glClearDepthf(CLEAR_D);
173 186
    GLES30.glClearStencil(CLEAR_S);
174 187

  
175
    for(int k = 0; k< DistortedLibrary.FBO_QUEUE_SIZE; k++)
188
    for(int k=0; k<queueSize; k++)
176 189
      {
177 190
      GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mBuffer[quality].mFBOH[k]);
178 191
      GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[quality].mColorH[2*k+1], 0);
src/main/java/org/distorted/library/main/InternalSurface.java
41 41
    mNumColors    = numcolors;
42 42
    mColorCreated = create;
43 43

  
44
    allocateColor();
45
    }
46

  
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

  
49
  void allocateColor()
50
    {
44 51
    int total = mNumFBOs*mNumColors;
45 52

  
46 53
    if( total>0 )

Also available in: Unified diff