Revision 5f35f1cb
Added by Leszek Koltunski almost 4 years ago
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 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
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)