Project

General

Profile

« Previous | Next » 

Revision 344ac0e4

Added by Leszek Koltunski almost 6 years ago

OIT: fix for 'out of memory' crash on Mali GPUs.

~The thing still does not fully work there - there are still strange flashes in apps that innvolve OIT, for example in 'Triblur'.

View differences:

src/main/java/org/distorted/library/main/DistortedEffects.java
78 78
    mAtomicCounter[0] = -1;
79 79
    }
80 80

  
81
  ///////////////////////////////////////////////////////////////
82
  // this has to be at least as big as the number of pixels in
83
  // the screen, lest the oitClear() pass overwrite memory.
81 84
  private static int mBufferSize=(0x1<<23);  // 8 million entries
82 85

  
83 86
  /// OIT CLEAR PROGRAM ///
......
126 129
///////////////////////////////////////////////////////////////////////////////////////////////////
127 130

  
128 131
  static void createProgram(Resources resources)
129
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
130 132
    {
131 133
    // MAIN PROGRAM ////////////////////////////////////
132 134
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
......
226 228
    if( mLinkedListSSBO[0]<0 )
227 229
      {
228 230
      GLES31.glGenBuffers(1,mLinkedListSSBO,0);
229
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
230 231
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
231 232
      GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW);
233
      GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]);
232 234
      GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
233 235
      }
234 236

  
......
470 472
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
471 473
    GLES31.glUniform2f(mOITClearTexCorrH, 1.0f, 1.0f );   // corrections do not really matter here - only present because of common vertex shader.
472 474
    GLES31.glUniform1f( mOITClearDepthH , 1.0f);          // likewise depth
473
    GLES31.glUniform2f(mOITClearSizeH, surface.mWidth, surface.mHeight);
475
    GLES31.glUniform2ui(mOITClearSizeH, surface.mWidth, surface.mHeight);
474 476
    GLES31.glVertexAttribPointer(mOITClearProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
475 477
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
476 478
    }
......
486 488
    GLES31.glUniform1i(mOITBuildTextureH, 0);
487 489
    GLES31.glUniform1i(mOITBuildDepthTextureH, 1);
488 490
    GLES31.glUniform2f(mOITBuildTexCorrH, corrW, corrH );
489
    GLES31.glUniform2f(mOITBuildSizeH, surface.mWidth, surface.mHeight);
491
    GLES31.glUniform2ui(mOITBuildSizeH, surface.mWidth, surface.mHeight);
490 492
    GLES31.glUniform1ui(mOITBuildNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 );  // see the fragment shader
491 493
    GLES31.glUniform1f(mOITBuildDepthH , 1.0f-surface.mNear);
492 494
    GLES31.glVertexAttribPointer(mOITBuildProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
......
503 505
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
504 506
    GLES31.glUniform1i(mOITCollapseDepthTextureH, 1);
505 507
    GLES31.glUniform2f(mOITCollapseTexCorrH, corrW, corrH );
506
    GLES31.glUniform2f(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
508
    GLES31.glUniform2ui(mOITCollapseSizeH, surface.mWidth, surface.mHeight);
507 509
    GLES31.glUniform1f( mOITCollapseDepthH , 1.0f-surface.mNear);
508 510
    GLES31.glVertexAttribPointer(mOITCollapseProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
509 511
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
......
518 520

  
519 521
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
520 522
    GLES31.glUniform2f(mOITRenderTexCorrH, corrW, corrH );
521
    GLES31.glUniform2f(mOITRenderSizeH, surface.mWidth, surface.mHeight);
523
    GLES31.glUniform2ui(mOITRenderSizeH, surface.mWidth, surface.mHeight);
522 524
    GLES31.glUniform1f( mOITRenderDepthH , 1.0f-surface.mNear);
523 525
    GLES31.glVertexAttribPointer(mOITRenderProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
524 526
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
525 527
    }
526 528

  
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528

  
529
  private static void analyzeBuffer(int w, int h)
530
    {
531
    int ptr, index;
532
    int errors = 0;
533

  
534
    GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]);
535
    ByteBuffer buf = (ByteBuffer)GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, mBufferSize*4, GLES31.GL_MAP_READ_BIT);
536
    IntBuffer intBuf = buf.order(ByteOrder.nativeOrder()).asIntBuffer();
537

  
538
    for(int col=0; col<w; col++)
539
      for(int row=0; row<h; row++)
540
        {
541
        index = col+row*w;
542
        ptr = intBuf.get(index);
543

  
544
        if( ptr!=0 )
545
          {
546
          if( ptr>0 && ptr<mBufferSize )
547
            {
548
            ptr = intBuf.get(ptr);
549
            if( ptr != index )
550
              {
551
              android.util.Log.d("surface", "col="+col+" row="+row+" val="+ptr+" expected: "+index);
552
              errors++;
553
              }
554
            }
555
          else
556
            {
557
            android.util.Log.d("surface", "overflow!");
558
            }
559
          }
560
        }
561

  
562
    GLES31.glUnmapBuffer(GLES31.GL_SHADER_STORAGE_BUFFER);
563
    GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, 0);
564

  
565
    if( errors>0 ) android.util.Log.e("surface", "errors: "+errors);
566
    }
567

  
568 529
///////////////////////////////////////////////////////////////////////////////////////////////////
569 530

  
570 531
  private void releasePriv()
571 532
    {
572
    if( !matrixCloned   )   mM.abortAll(false);
573
    if( !vertexCloned   )   mV.abortAll(false);
574
    if( !fragmentCloned )   mF.abortAll(false);
575
    if( !postprocessCloned) mP.abortAll(false);
533
    if( !matrixCloned      ) mM.abortAll(false);
534
    if( !vertexCloned      ) mV.abortAll(false);
535
    if( !fragmentCloned    ) mF.abortAll(false);
536
    if( !postprocessCloned ) mP.abortAll(false);
576 537

  
577 538
    mM = null;
578 539
    mV = null;

Also available in: Unified diff