aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-02-14 16:39:56 -0800
committerSiva Velusamy <vsiva@google.com>2012-02-14 16:40:59 -0800
commitfaf7b68609a860c9f818bc7c8c01c14a3d969e18 (patch)
tree3293ffaf752d3188dcbc95ddebeee54a01b02ef0 /eclipse
parent6a8e5546f2946e544cf170e178ea86ba27c99bce (diff)
downloadsdk-faf7b68609a860c9f818bc7c8c01c14a3d969e18.zip
sdk-faf7b68609a860c9f818bc7c8c01c14a3d969e18.tar.gz
sdk-faf7b68609a860c9f818bc7c8c01c14a3d969e18.tar.bz2
gltrace: Add support for shader uniforms.
This patch adds the necessary state and transformations to support uniforms used in shaders. Change-Id: Ibf93098977d8f8a733d6572b1524ff50eda28b6f
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/CollectTraceAction.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java66
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java31
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java12
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java60
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java14
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java177
7 files changed, 357 insertions, 7 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/CollectTraceAction.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/CollectTraceAction.java
index 04916b5..58e78b4 100644
--- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/CollectTraceAction.java
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/CollectTraceAction.java
@@ -206,9 +206,9 @@ public class CollectTraceAction implements IWorkbenchWindowActionDelegate {
}
private void disableGLTrace(IDevice device) {
- // The only way to disable is by enabling tracing with an empty package name
+ // The only way to disable is by enabling tracing with an invalid package name
try {
- setGLTraceOn(device, "");
+ setGLTraceOn(device, "no.such.package"); //$NON-NLS-1$
} catch (Exception e) {
// ignore any exception
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java
new file mode 100644
index 0000000..84ad6ec
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLObjectProperty.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.gltrace.state;
+
+import com.google.common.base.Joiner;
+
+import java.util.List;
+
+public class GLObjectProperty extends GLAbstractAtomicProperty {
+ private final Object mDefaultValue;
+ private Object mCurrentValue;
+
+ private static final Joiner JOINER = Joiner.on(", "); //$NON-NLS-1$
+
+ public GLObjectProperty(GLStateType type, Object defaultValue) {
+ super(type);
+
+ mDefaultValue = mCurrentValue = defaultValue;
+ }
+
+ @Override
+ public boolean isDefault() {
+ return mDefaultValue == mCurrentValue;
+ }
+
+ @Override
+ public void setValue(Object newValue) {
+ mCurrentValue = newValue;
+ }
+
+ @Override
+ public String getStringValue() {
+ if (mCurrentValue == null) {
+ return "null";
+ } else {
+ if (mCurrentValue instanceof List<?>) {
+ return "[" + JOINER.join((List<?>) mCurrentValue) + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return mCurrentValue.toString();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getType() + "=" + getStringValue(); //$NON-NLS-1$
+ }
+
+ @Override
+ public Object getValue() {
+ return mCurrentValue;
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java
index c5bbd0b..dfc922a 100644
--- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLState.java
@@ -19,6 +19,8 @@ package com.android.ide.eclipse.gltrace.state;
import com.android.ide.eclipse.gldebugger.GLEnum;
import com.android.ide.eclipse.gltrace.state.GLIntegerProperty.DisplayRadix;
+import java.util.Collections;
+
public class GLState {
/** # of texture units modelled in the GL State. */
public static final int TEXTURE_UNIT_COUNT = 8;
@@ -252,12 +254,37 @@ public class GLState {
IGLProperty attachedShaders = new GLSparseArrayProperty(GLStateType.ATTACHED_SHADERS,
attachedShaderId);
+ IGLProperty attributeName = new GLStringProperty(GLStateType.ATTRIBUTE_NAME, "");
+ IGLProperty attributeType = new GLEnumProperty(GLStateType.ATTRIBUTE_TYPE,
+ GLEnum.GL_FLOAT_MAT4);
+ IGLProperty attributeSize = new GLIntegerProperty(GLStateType.ATTRIBUTE_SIZE,
+ Integer.valueOf(1));
+ IGLProperty attributeValue = new GLObjectProperty(GLStateType.ATTRIBUTE_VALUE,
+ Collections.emptyList());
+ IGLProperty perAttributeProperty = new GLCompositeProperty(GLStateType.PER_ATTRIBUTE_STATE,
+ attributeName, attributeType, attributeSize, attributeValue);
+ IGLProperty attributes = new GLSparseArrayProperty(GLStateType.ACTIVE_ATTRIBUTES,
+ perAttributeProperty);
+
+ IGLProperty uniformName = new GLStringProperty(GLStateType.UNIFORM_NAME, "");
+ IGLProperty uniformType = new GLEnumProperty(GLStateType.UNIFORM_TYPE,
+ GLEnum.GL_FLOAT_MAT4);
+ IGLProperty uniformSize = new GLIntegerProperty(GLStateType.UNIFORM_SIZE,
+ Integer.valueOf(1));
+ IGLProperty uniformValue = new GLObjectProperty(GLStateType.UNIFORM_VALUE,
+ Collections.emptyList());
+ IGLProperty perUniformProperty = new GLCompositeProperty(GLStateType.PER_UNIFORM_STATE,
+ uniformName, uniformType, uniformSize, uniformValue);
+ IGLProperty uniforms = new GLSparseArrayProperty(GLStateType.ACTIVE_UNIFORMS,
+ perUniformProperty);
+
IGLProperty perProgramState = new GLCompositeProperty(GLStateType.PER_PROGRAM_STATE,
- attachedShaders);
+ attachedShaders, attributes, uniforms);
IGLProperty programs = new GLSparseArrayProperty(GLStateType.PROGRAMS, perProgramState);
- return new GLCompositeProperty(GLStateType.PROGRAM_STATE, currentProgram, programs);
+ return new GLCompositeProperty(GLStateType.PROGRAM_STATE,
+ currentProgram, programs);
}
private IGLProperty createShaderState() {
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java
index 4e0decb..42016fa 100644
--- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/GLStateType.java
@@ -120,6 +120,18 @@ public enum GLStateType {
PER_PROGRAM_STATE("Per Program State"),
ATTACHED_SHADERS("Attached Shaders"),
ATTACHED_SHADER_ID("Attached Shader ID"),
+ ACTIVE_ATTRIBUTES("Attributes"),
+ PER_ATTRIBUTE_STATE("Per Attribute State"),
+ ATTRIBUTE_NAME("Name"),
+ ATTRIBUTE_TYPE("Type"),
+ ATTRIBUTE_SIZE("Size"),
+ ATTRIBUTE_VALUE("Value"),
+ ACTIVE_UNIFORMS("Uniforms"),
+ PER_UNIFORM_STATE("Per Uniform State"),
+ UNIFORM_NAME("Name"),
+ UNIFORM_TYPE("Type"),
+ UNIFORM_SIZE("Size"),
+ UNIFORM_VALUE("Value"),
SHADERS("Shader Objects"),
PER_SHADER_STATE("Per Shader State"),
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java
new file mode 100644
index 0000000..b977d87
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/CurrentProgramPropertyAccessor.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.eclipse.gltrace.state.transforms;
+
+import com.android.ide.eclipse.gltrace.state.GLIntegerProperty;
+import com.android.ide.eclipse.gltrace.state.GLStateType;
+import com.android.ide.eclipse.gltrace.state.IGLProperty;
+
+public class CurrentProgramPropertyAccessor implements IGLPropertyAccessor {
+ private final int mContextId;
+ private final GLStateType mStateCategory;
+ private final int mLocation;
+ private final GLStateType mStateType;
+ private final IGLPropertyAccessor mCurrentProgramAccessor;
+
+ public CurrentProgramPropertyAccessor(int contextid, GLStateType stateCategory,
+ int location, GLStateType stateType) {
+ mContextId = contextid;
+ mStateCategory = stateCategory;
+ mLocation = location;
+ mStateType = stateType;
+
+ mCurrentProgramAccessor = GLPropertyAccessor.makeAccessor(contextid,
+ GLStateType.PROGRAM_STATE,
+ GLStateType.CURRENT_PROGRAM);
+ }
+ @Override
+ public IGLProperty getProperty(IGLProperty state) {
+ // obtain the current program
+ IGLProperty currentProgramProperty = mCurrentProgramAccessor.getProperty(state);
+ if (!(currentProgramProperty instanceof GLIntegerProperty)) {
+ return null;
+ }
+
+ Integer program = (Integer) currentProgramProperty.getValue();
+
+ // now access the required program property
+ return GLPropertyAccessor.makeAccessor(mContextId,
+ GLStateType.PROGRAM_STATE,
+ GLStateType.PROGRAMS,
+ program,
+ mStateCategory,
+ Integer.valueOf(mLocation),
+ mStateType).getProperty(state);
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java
index 1d6be8c..b7547bc 100644
--- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/SparseArrayElementAddTransform.java
@@ -21,11 +21,12 @@ import com.android.ide.eclipse.gltrace.state.IGLProperty;
/**
* A {@link SparseArrayElementAddTransform} changes given state by adding an
- * element to a sparse array.
+ * element to a sparse array, if there is no item with the same key already.
*/
public class SparseArrayElementAddTransform implements IStateTransform {
private IGLPropertyAccessor mAccessor;
private int mKey;
+ private IGLProperty mOldValue;
public SparseArrayElementAddTransform(IGLPropertyAccessor accessor, int key) {
mAccessor = accessor;
@@ -36,7 +37,11 @@ public class SparseArrayElementAddTransform implements IStateTransform {
public void apply(IGLProperty currentState) {
GLSparseArrayProperty propertyArray = getArray(currentState);
if (propertyArray != null) {
- propertyArray.add(mKey);
+ mOldValue = propertyArray.getProperty(mKey);
+ if (mOldValue == null) {
+ // add only if there is no item with this key already present
+ propertyArray.add(mKey);
+ }
}
}
@@ -44,7 +49,10 @@ public class SparseArrayElementAddTransform implements IStateTransform {
public void revert(IGLProperty currentState) {
GLSparseArrayProperty propertyArray = getArray(currentState);
if (propertyArray != null) {
- propertyArray.delete(mKey);
+ if (mOldValue == null) {
+ // delete only if we actually added this key
+ propertyArray.delete(mKey);
+ }
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java
index d248bd7..3cc1004 100644
--- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java
+++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/state/transforms/StateTransformFactory.java
@@ -105,6 +105,34 @@ public class StateTransformFactory {
return transformsForGlAttachShader(msg);
case glDetachShader:
return transformsForGlDetachShader(msg);
+ case glGetActiveAttrib:
+ return transformsForGlGetActiveAttrib(msg);
+ case glGetActiveUniform:
+ return transformsForGlGetActiveUniform(msg);
+ case glUniform1i:
+ case glUniform2i:
+ case glUniform3i:
+ case glUniform4i:
+ return transformsForGlUniform(msg, false);
+ case glUniform1f:
+ case glUniform2f:
+ case glUniform3f:
+ case glUniform4f:
+ return transformsForGlUniform(msg, true);
+ case glUniform1iv:
+ case glUniform2iv:
+ case glUniform3iv:
+ case glUniform4iv:
+ return transformsForGlUniformv(msg, false);
+ case glUniform1fv:
+ case glUniform2fv:
+ case glUniform3fv:
+ case glUniform4fv:
+ return transformsForGlUniformv(msg, true);
+ case glUniformMatrix2fv:
+ case glUniformMatrix3fv:
+ case glUniformMatrix4fv:
+ return transformsForGlUniformMatrix(msg);
// Shader State Transformations
case glCreateShader:
@@ -863,6 +891,155 @@ public class StateTransformFactory {
return Collections.singletonList(transform);
}
+ private static List<IStateTransform> transformsForGlGetActiveAttribOrUniform(
+ GLMessage msg, boolean isAttrib) {
+ // void glGetActive[Attrib|Uniform](GLuint program, GLuint index, GLsizei bufsize,
+ // GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+ int program = msg.getArgs(0).getIntValue(0);
+ int size = msg.getArgs(4).getIntValue(0);
+ GLEnum type = GLEnum.valueOf(msg.getArgs(5).getIntValue(0));
+ String name = msg.getArgs(6).getCharValue(0).toStringUtf8();
+
+ // The 2nd argument (index) does not give the correct location of the
+ // attribute/uniform in device. The actual location is obtained from
+ // the getAttribLocation or getUniformLocation calls. The trace library
+ // appends this value as an additional last argument to this call.
+ int location = msg.getArgs(7).getIntValue(0);
+
+ GLStateType activeInput;
+ GLStateType inputName;
+ GLStateType inputType;
+ GLStateType inputSize;
+
+ if (isAttrib) {
+ activeInput = GLStateType.ACTIVE_ATTRIBUTES;
+ inputName = GLStateType.ATTRIBUTE_NAME;
+ inputType = GLStateType.ATTRIBUTE_TYPE;
+ inputSize = GLStateType.ATTRIBUTE_SIZE;
+ } else {
+ activeInput = GLStateType.ACTIVE_UNIFORMS;
+ inputName = GLStateType.UNIFORM_NAME;
+ inputType = GLStateType.UNIFORM_TYPE;
+ inputSize = GLStateType.UNIFORM_SIZE;
+ }
+
+ IStateTransform addAttribute = new SparseArrayElementAddTransform(
+ GLPropertyAccessor.makeAccessor(msg.getContextId(),
+ GLStateType.PROGRAM_STATE,
+ GLStateType.PROGRAMS,
+ Integer.valueOf(program),
+ activeInput),
+ Integer.valueOf(location));
+ IStateTransform setAttributeName = new PropertyChangeTransform(
+ GLPropertyAccessor.makeAccessor(msg.getContextId(),
+ GLStateType.PROGRAM_STATE,
+ GLStateType.PROGRAMS,
+ Integer.valueOf(program),
+ activeInput,
+ Integer.valueOf(location),
+ inputName),
+ name);
+ IStateTransform setAttributeType = new PropertyChangeTransform(
+ GLPropertyAccessor.makeAccessor(msg.getContextId(),
+ GLStateType.PROGRAM_STATE,
+ GLStateType.PROGRAMS,
+ Integer.valueOf(program),
+ activeInput,
+ Integer.valueOf(location),
+ inputType),
+ type);
+ IStateTransform setAttributeSize = new PropertyChangeTransform(
+ GLPropertyAccessor.makeAccessor(msg.getContextId(),
+ GLStateType.PROGRAM_STATE,
+ GLStateType.PROGRAMS,
+ Integer.valueOf(program),
+ activeInput,
+ Integer.valueOf(location),
+ inputSize),
+ Integer.valueOf(size));
+ return Arrays.asList(addAttribute, setAttributeName, setAttributeType, setAttributeSize);
+ }
+
+ private static List<IStateTransform> transformsForGlGetActiveAttrib(GLMessage msg) {
+ return transformsForGlGetActiveAttribOrUniform(msg, true);
+ }
+
+ private static List<IStateTransform> transformsForGlGetActiveUniform(GLMessage msg) {
+ return transformsForGlGetActiveAttribOrUniform(msg, false);
+ }
+
+ private static List<IStateTransform> transformsForGlUniformMatrix(GLMessage msg) {
+ // void glUniformMatrix[2|3|4]fv(GLint location, GLsizei count, GLboolean transpose,
+ // const GLfloat *value);
+ int location = msg.getArgs(0).getIntValue(0);
+ List<Float> uniforms = msg.getArgs(3).getFloatValueList();
+
+ IStateTransform setValues = new PropertyChangeTransform(
+ new CurrentProgramPropertyAccessor(msg.getContextId(),
+ GLStateType.ACTIVE_UNIFORMS,
+ location,
+ GLStateType.UNIFORM_VALUE),
+ uniforms);
+
+ return Collections.singletonList(setValues);
+ }
+
+ private static List<IStateTransform> transformsForGlUniformv(GLMessage msg, boolean isFloats) {
+ // void glUniform1fv(GLint location, GLsizei count, const GLfloat *value);
+ int location = msg.getArgs(0).getIntValue(0);
+ List<?> uniforms;
+ if (isFloats) {
+ uniforms = msg.getArgs(2).getFloatValueList();
+ } else {
+ uniforms = msg.getArgs(2).getIntValueList();
+ }
+
+ IStateTransform setValues = new PropertyChangeTransform(
+ new CurrentProgramPropertyAccessor(msg.getContextId(),
+ GLStateType.ACTIVE_UNIFORMS,
+ location,
+ GLStateType.UNIFORM_VALUE),
+ uniforms);
+
+ return Collections.singletonList(setValues);
+ }
+
+ private static List<IStateTransform> transformsForGlUniform(GLMessage msg, boolean isFloats) {
+ // void glUniform1f(GLint location, GLfloat v0);
+ // void glUniform2f(GLint location, GLfloat v0, GLfloat v1);
+ // .. 3f
+ // .. 4f
+ // void glUniform1i(GLint location, GLfloat v0);
+ // void glUniform2i(GLint location, GLfloat v0, GLfloat v1);
+ // .. 3i
+ // .. 4i
+
+ int location = msg.getArgs(0).getIntValue(0);
+ List<?> uniforms;
+ if (isFloats) {
+ List<Float> args = new ArrayList<Float>(msg.getArgsCount() - 1);
+ for (int i = 1; i < msg.getArgsCount(); i++) {
+ args.add(Float.valueOf(msg.getArgs(1).getFloatValue(0)));
+ }
+ uniforms = args;
+ } else {
+ List<Integer> args = new ArrayList<Integer>(msg.getArgsCount() - 1);
+ for (int i = 1; i < msg.getArgsCount(); i++) {
+ args.add(Integer.valueOf(msg.getArgs(1).getIntValue(0)));
+ }
+ uniforms = args;
+ }
+
+ IStateTransform setValues = new PropertyChangeTransform(
+ new CurrentProgramPropertyAccessor(msg.getContextId(),
+ GLStateType.ACTIVE_UNIFORMS,
+ location,
+ GLStateType.UNIFORM_VALUE),
+ uniforms);
+
+ return Collections.singletonList(setValues);
+ }
+
private static List<IStateTransform> transformsForGlCreateShader(GLMessage msg) {
// GLuint glCreateShader(GLenum shaderType);
GLEnum shaderType = GLEnum.valueOf(msg.getArgs(0).getIntValue(0));