Skip to content

Commit 1c99a99

Browse files
committed
Revert "Reapply "Implement GPU timer query support across multiple platforms and handle unsupported cases""
This reverts commit 4bf14ab.
1 parent 4bf14ab commit 1c99a99

6 files changed

Lines changed: 23 additions & 99 deletions

File tree

jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ public void glAttachShader(int program, int shader) {
100100

101101
@Override
102102
public void glBeginQuery(int target, int query) {
103-
if (target == GL.GL_TIME_ELAPSED) {
104-
throw new UnsupportedOperationException("64-bit GPU timer queries are not exposed by the Android GLES bindings");
105-
}
106103
GLES30.glBeginQuery(target, query);
107104
}
108105

@@ -290,9 +287,6 @@ public void glEnableVertexAttribArray(int index) {
290287

291288
@Override
292289
public void glEndQuery(int target) {
293-
if (target == GL.GL_TIME_ELAPSED) {
294-
throw new UnsupportedOperationException("64-bit GPU timer queries are not exposed by the Android GLES bindings");
295-
}
296290
GLES30.glEndQuery(target);
297291
}
298292

@@ -354,7 +348,10 @@ public String glGetProgramInfoLog(int program, int maxLength) {
354348

355349
@Override
356350
public long glGetQueryObjectui64(int query, int pname) {
357-
throw new UnsupportedOperationException("64-bit query results are not exposed by the Android GLES bindings");
351+
IntBuffer buff = (IntBuffer)tmpBuff.clear();
352+
//FIXME This is wrong IMO should be glGetQueryObjectui64v with a LongBuffer but it seems the API doesn't provide it.
353+
GLES30.glGetQueryObjectuiv(query, pname, buff);
354+
return buff.get(0);
358355
}
359356

360357
@Override

jme3-core/src/main/java/com/jme3/app/DetailedProfiler.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
package com.jme3.app;
3333

3434
import com.jme3.profile.*;
35-
import com.jme3.renderer.Caps;
3635
import com.jme3.renderer.Renderer;
3736
import com.jme3.renderer.ViewPort;
3837
import com.jme3.renderer.queue.RenderQueue;
@@ -87,16 +86,14 @@ public void appStep(AppStep step) {
8786
frameTime.setNewFrameValueCpu(System.nanoTime());
8887

8988
frameEnded = false;
90-
if (renderer != null) {
91-
for (StatLine statLine : data.values()) {
92-
for (Iterator<Integer> i = statLine.taskIds.iterator(); i.hasNext(); ) {
93-
int id = i.next();
94-
if (renderer.isTaskResultAvailable(id)) {
95-
long val = renderer.getProfilingTime(id);
96-
statLine.setValueGpu(val);
97-
i.remove();
98-
idsPool.push(id);
99-
}
89+
for (StatLine statLine : data.values()) {
90+
for (Iterator<Integer> i = statLine.taskIds.iterator(); i.hasNext(); ) {
91+
int id = i.next();
92+
if (renderer.isTaskResultAvailable(id)) {
93+
long val = renderer.getProfilingTime(id);
94+
statLine.setValueGpu(val);
95+
i.remove();
96+
idsPool.push(id);
10097
}
10198
}
10299
}
@@ -225,8 +222,8 @@ private void addStep(String path, long value) {
225222
int id = getUnusedTaskId();
226223
line.taskIds.add(id);
227224
renderer.startProfiling(id);
228-
ongoingGpuProfiling = true;
229225
}
226+
ongoingGpuProfiling = true;
230227
prevPath = path;
231228

232229
}
@@ -242,13 +239,8 @@ private String getPath(String step, String... subPath) {
242239
}
243240

244241
public void setRenderer(Renderer renderer) {
245-
idsPool.clear();
246-
if (renderer != null && renderer.getCaps().contains(Caps.GpuTimerQuery)) {
247-
this.renderer = renderer;
248-
poolTaskIds(renderer);
249-
} else {
250-
this.renderer = null;
251-
}
242+
this.renderer = renderer;
243+
poolTaskIds(renderer);
252244
}
253245

254246
private void poolTaskIds(Renderer renderer) {

jme3-core/src/main/java/com/jme3/renderer/Caps.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,6 @@ public enum Caps {
467467
* GPU support for binary shaders.
468468
*/
469469
BinaryShader,
470-
471-
/**
472-
* Supports GPU timer queries with full 64-bit elapsed-time results.
473-
*/
474-
GpuTimerQuery,
475-
476470
/**
477471
* Supporting working with UniformBufferObject.
478472
*/

jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,6 @@ private boolean hasAnyExtension(String... extensionNames) {
247247
return false;
248248
}
249249

250-
private boolean hasGpuTimerQuerySupport() {
251-
if (caps.contains(Caps.OpenGL33) || hasExtension("GL_ARB_timer_query")) {
252-
return true;
253-
}
254-
255-
Platform.Os os = JmeSystem.getPlatform().getOs();
256-
boolean glesBindingSupports64BitTimerQuery = os != Platform.Os.Android && os != Platform.Os.iOS;
257-
return caps.contains(Caps.OpenGLES20)
258-
&& hasExtension("GL_EXT_disjoint_timer_query")
259-
&& glesBindingSupports64BitTimerQuery;
260-
}
261-
262250
private void loadCapabilitiesES() {
263251
String version = gl.glGetString(GL.GL_VERSION);
264252
int oglVer = extractVersion(version);
@@ -693,10 +681,6 @@ && hasExtension("GL_ARB_half_float_pixel"))
693681
}
694682
}
695683

696-
if (hasGpuTimerQuerySupport()) {
697-
caps.add(Caps.GpuTimerQuery);
698-
}
699-
700684
if (hasExtension("GL_OES_geometry_shader") || hasExtension("GL_EXT_geometry_shader")) {
701685
caps.add(Caps.GeometryShader);
702686
}
@@ -3844,43 +3828,28 @@ public void setLinearizeSrgbImages(boolean linearize) {
38443828

38453829
@Override
38463830
public int[] generateProfilingTasks(int numTasks) {
3847-
if (!caps.contains(Caps.GpuTimerQuery)) {
3848-
throw new RendererException("GPU timer queries are not supported by the current renderer");
3849-
}
38503831
IntBuffer ids = BufferUtils.createIntBuffer(numTasks);
38513832
gl.glGenQueries(numTasks, ids);
38523833
return BufferUtils.getIntArray(ids);
38533834
}
38543835

38553836
@Override
38563837
public void startProfiling(int taskId) {
3857-
if (!caps.contains(Caps.GpuTimerQuery)) {
3858-
throw new RendererException("GPU timer queries are not supported by the current renderer");
3859-
}
38603838
gl.glBeginQuery(GL.GL_TIME_ELAPSED, taskId);
38613839
}
38623840

38633841
@Override
38643842
public void stopProfiling() {
3865-
if (!caps.contains(Caps.GpuTimerQuery)) {
3866-
throw new RendererException("GPU timer queries are not supported by the current renderer");
3867-
}
38683843
gl.glEndQuery(GL.GL_TIME_ELAPSED);
38693844
}
38703845

38713846
@Override
38723847
public long getProfilingTime(int taskId) {
3873-
if (!caps.contains(Caps.GpuTimerQuery)) {
3874-
throw new RendererException("GPU timer queries are not supported by the current renderer");
3875-
}
38763848
return gl.glGetQueryObjectui64(taskId, GL.GL_QUERY_RESULT);
38773849
}
38783850

38793851
@Override
38803852
public boolean isTaskResultAvailable(int taskId) {
3881-
if (!caps.contains(Caps.GpuTimerQuery)) {
3882-
throw new RendererException("GPU timer queries are not supported by the current renderer");
3883-
}
38843853
return gl.glGetQueryObjectiv(taskId, GL.GL_QUERY_RESULT_AVAILABLE) == 1;
38853854
}
38863855

jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class IosGL implements GL, GL2, GLES_30, GLExt, GLFbo {
5959
@Override
6060
public void resetStats() {
6161
}
62-
62+
6363
private static int getLimitBytes(ByteBuffer buffer) {
6464
checkLimit(buffer);
6565
return buffer.limit();
@@ -143,9 +143,6 @@ public void glAttachShader(int program, int shader) {
143143

144144
@Override
145145
public void glBeginQuery(int target, int query) {
146-
if (target == GL.GL_TIME_ELAPSED) {
147-
throw new UnsupportedOperationException("64-bit GPU timer queries are not implemented by the iOS GLES binding");
148-
}
149146
JmeIosGLES.glBeginQuery(target, query);
150147
}
151148

@@ -336,9 +333,6 @@ public void glEnableVertexAttribArray(int index) {
336333

337334
@Override
338335
public void glEndQuery(int target) {
339-
if (target == GL.GL_TIME_ELAPSED) {
340-
throw new UnsupportedOperationException("64-bit GPU timer queries are not implemented by the iOS GLES binding");
341-
}
342336
JmeIosGLES.glEndQuery(target);
343337
}
344338

@@ -404,7 +398,8 @@ public String glGetProgramInfoLog(int program, int maxLength) {
404398

405399
@Override
406400
public long glGetQueryObjectui64(int query, int pname) {
407-
throw new UnsupportedOperationException("64-bit query results are not implemented by the iOS GLES binding");
401+
JmeIosGLES.glGetQueryObjectuiv(query, pname, temp_array);
402+
return temp_array[0];
408403
}
409404

410405
@Override

jme3-lwjgl3/src/main/java/com/jme3/renderer/lwjgl/LwjglGLES.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
import java.nio.IntBuffer;
1515
import java.nio.ShortBuffer;
1616

17-
import org.lwjgl.opengles.GLES;
1817
import org.lwjgl.opengles.GLES20;
1918
import org.lwjgl.opengles.GLES30;
2019
import org.lwjgl.opengles.GLES31;
21-
import org.lwjgl.opengles.EXTDisjointTimerQuery;
2220

2321

2422
/**
@@ -35,6 +33,7 @@ public class LwjglGLES extends LwjglRender implements GL, GL2, GLES_30, GLExt, G
3533
public void resetStats() {
3634
}
3735

36+
3837
public static void checkLimit(Buffer buffer) {
3938
if (buffer == null) return;
4039
if (buffer.limit() == 0) {
@@ -539,25 +538,11 @@ public void glViewport(int x, int y, int width, int height) {
539538

540539
@Override
541540
public void glBeginQuery(int target, int query) {
542-
if (target == GL.GL_TIME_ELAPSED) {
543-
if (!GLES.getCapabilities().GL_EXT_disjoint_timer_query) {
544-
throw new UnsupportedOperationException("GL_TIME_ELAPSED requires GL_EXT_disjoint_timer_query");
545-
}
546-
EXTDisjointTimerQuery.glBeginQueryEXT(target, query);
547-
return;
548-
}
549541
GLES30.glBeginQuery(target, query);
550542
}
551543

552544
@Override
553545
public void glEndQuery(int target) {
554-
if (target == GL.GL_TIME_ELAPSED) {
555-
if (!GLES.getCapabilities().GL_EXT_disjoint_timer_query) {
556-
throw new UnsupportedOperationException("GL_TIME_ELAPSED requires GL_EXT_disjoint_timer_query");
557-
}
558-
EXTDisjointTimerQuery.glEndQueryEXT(target);
559-
return;
560-
}
561546
GLES30.glEndQuery(target);
562547
}
563548

@@ -567,30 +552,22 @@ public void glGenQueries(int num, IntBuffer buff) {
567552
int oldLimit = buff.limit();
568553
int pos = buff.position();
569554
buff.limit(pos + num);
570-
if (GLES.getCapabilities().GL_EXT_disjoint_timer_query) {
571-
EXTDisjointTimerQuery.glGenQueriesEXT(buff);
572-
} else {
573-
GLES30.glGenQueries(buff);
574-
}
555+
GLES30.glGenQueries(buff);
575556
buff.limit(oldLimit);
576557
}
577558

578559
@Override
579560
public int glGetQueryObjectiv(int query, int pname) {
580-
if (GLES.getCapabilities().GL_EXT_disjoint_timer_query) {
581-
return EXTDisjointTimerQuery.glGetQueryObjectiEXT(query, pname);
582-
}
583561
IntBuffer b = (IntBuffer) tmpBuff.clear();
584562
GLES30.glGetQueryObjectuiv(query, pname, b);
585563
return b.get(0);
586564
}
587565

588566
@Override
589567
public long glGetQueryObjectui64(int query, int pname) {
590-
if (!GLES.getCapabilities().GL_EXT_disjoint_timer_query) {
591-
throw new UnsupportedOperationException("64-bit query results require GL_EXT_disjoint_timer_query");
592-
}
593-
return EXTDisjointTimerQuery.glGetQueryObjectui64EXT(query, pname);
568+
IntBuffer b = (IntBuffer) tmpBuff.clear();
569+
GLES30.glGetQueryObjectuiv(query, pname, b);
570+
return b.get(0) & 0xFFFFFFFFL;
594571
}
595572

596573
@Override

0 commit comments

Comments
 (0)