summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2011-12-28 13:47:05 -0800
committerAlex Sakhartchouk <alexst@google.com>2011-12-28 13:47:05 -0800
commit36a7d6003d521e6aff16e2a1e74f19ea9ec00624 (patch)
tree4678462dbf3c0ab34be1d4d5eba45a2298f28c79
parenta041adcb85838ed5dedd811524a1831f964f0fac (diff)
downloadframeworks_base-36a7d6003d521e6aff16e2a1e74f19ea9ec00624.zip
frameworks_base-36a7d6003d521e6aff16e2a1e74f19ea9ec00624.tar.gz
frameworks_base-36a7d6003d521e6aff16e2a1e74f19ea9ec00624.tar.bz2
Adding RS comments, cleaning up the gl implementation with new Element hal.
Change-Id: I74de1e8248a73a45a39976e6027dac2626d580e9
-rw-r--r--libs/rs/driver/rsdMeshObj.cpp27
-rw-r--r--libs/rs/driver/rsdShader.cpp93
-rw-r--r--libs/rs/rsElement.h9
-rw-r--r--libs/rs/rsMesh.h9
-rw-r--r--libs/rs/rsType.h9
5 files changed, 73 insertions, 74 deletions
diff --git a/libs/rs/driver/rsdMeshObj.cpp b/libs/rs/driver/rsdMeshObj.cpp
index 24a7183..9ac6383 100644
--- a/libs/rs/driver/rsdMeshObj.cpp
+++ b/libs/rs/driver/rsdMeshObj.cpp
@@ -50,14 +50,9 @@ RsdMeshObj::~RsdMeshObj() {
}
bool RsdMeshObj::isValidGLComponent(const Element *elem, uint32_t fieldIdx) {
- // Do not create attribs for padding
- if (elem->getFieldName(fieldIdx)[0] == '#') {
- return false;
- }
-
// Only GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FIXED, GL_FLOAT are accepted.
// Filter rs types accordingly
- RsDataType dt = elem->getField(fieldIdx)->getComponent().getType();
+ RsDataType dt = elem->mHal.state.fields[fieldIdx]->mHal.state.dataType;
if (dt != RS_TYPE_FLOAT_32 && dt != RS_TYPE_UNSIGNED_8 &&
dt != RS_TYPE_UNSIGNED_16 && dt != RS_TYPE_SIGNED_8 &&
dt != RS_TYPE_SIGNED_16) {
@@ -65,7 +60,7 @@ bool RsdMeshObj::isValidGLComponent(const Element *elem, uint32_t fieldIdx) {
}
// Now make sure they are not arrays
- uint32_t arraySize = elem->getFieldArraySize(fieldIdx);
+ uint32_t arraySize = elem->mHal.state.fieldArraySizes[fieldIdx];
if (arraySize != 1) {
return false;
}
@@ -81,7 +76,7 @@ bool RsdMeshObj::init() {
mAttribCount = 0;
for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) {
const Element *elem = mRSMesh->mHal.state.vertexBuffers[ct]->getType()->getElement();
- for (uint32_t ct=0; ct < elem->getFieldCount(); ct++) {
+ for (uint32_t ct=0; ct < elem->mHal.state.fieldsCount; ct++) {
if (isValidGLComponent(elem, ct)) {
mAttribCount ++;
}
@@ -104,21 +99,21 @@ bool RsdMeshObj::init() {
uint32_t userNum = 0;
for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) {
const Element *elem = mRSMesh->mHal.state.vertexBuffers[ct]->getType()->getElement();
- uint32_t stride = elem->getSizeBytes();
- for (uint32_t fieldI=0; fieldI < elem->getFieldCount(); fieldI++) {
- const Component &c = elem->getField(fieldI)->getComponent();
+ uint32_t stride = elem->mHal.state.elementSizeBytes;
+ for (uint32_t fieldI=0; fieldI < elem->mHal.state.fieldsCount; fieldI++) {
+ const Element *f = elem->mHal.state.fields[fieldI];
if (!isValidGLComponent(elem, fieldI)) {
continue;
}
- mAttribs[userNum].size = c.getVectorSize();
- mAttribs[userNum].offset = elem->getFieldOffsetBytes(fieldI);
- mAttribs[userNum].type = rsdTypeToGLType(c.getType());
- mAttribs[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized();
+ mAttribs[userNum].size = f->mHal.state.vectorSize;
+ mAttribs[userNum].offset = elem->mHal.state.fieldOffsetBytes[fieldI];
+ mAttribs[userNum].type = rsdTypeToGLType(f->mHal.state.dataType);
+ mAttribs[userNum].normalized = f->mHal.state.dataType != RS_TYPE_FLOAT_32;
mAttribs[userNum].stride = stride;
String8 tmp(RS_SHADER_ATTR);
- tmp.append(elem->getFieldName(fieldI));
+ tmp.append(elem->mHal.state.fieldNames[fieldI]);
mAttribs[userNum].name.setTo(tmp.string());
// Remember which allocation this attribute came from
diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp
index e9ce7c2..6265074 100644
--- a/libs/rs/driver/rsdShader.cpp
+++ b/libs/rs/driver/rsdShader.cpp
@@ -90,12 +90,12 @@ String8 RsdShader::getGLSLInputString() const {
String8 s;
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
const Element *e = mRSProgram->mHal.state.inputElements[ct];
- for (uint32_t field=0; field < e->getFieldCount(); field++) {
- const Element *f = e->getField(field);
+ for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) {
+ const Element *f = e->mHal.state.fields[field];
// Cannot be complex
- rsAssert(!f->getFieldCount());
- switch (f->getComponent().getVectorSize()) {
+ rsAssert(!f->mHal.state.fieldsCount);
+ switch (f->mHal.state.vectorSize) {
case 1: s.append("attribute float ATTRIB_"); break;
case 2: s.append("attribute vec2 ATTRIB_"); break;
case 3: s.append("attribute vec3 ATTRIB_"); break;
@@ -104,7 +104,7 @@ String8 RsdShader::getGLSLInputString() const {
rsAssert(0);
}
- s.append(e->getFieldName(field));
+ s.append(e->mHal.state.fieldNames[field]);
s.append(";\n");
}
}
@@ -114,17 +114,13 @@ String8 RsdShader::getGLSLInputString() const {
void RsdShader::appendAttributes() {
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
const Element *e = mRSProgram->mHal.state.inputElements[ct];
- for (uint32_t field=0; field < e->getFieldCount(); field++) {
- const Element *f = e->getField(field);
- const char *fn = e->getFieldName(field);
-
- if (fn[0] == '#') {
- continue;
- }
+ for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) {
+ const Element *f = e->mHal.state.fields[field];
+ const char *fn = e->mHal.state.fieldNames[field];
// Cannot be complex
- rsAssert(!f->getFieldCount());
- switch (f->getComponent().getVectorSize()) {
+ rsAssert(!f->mHal.state.fieldsCount);
+ switch (f->mHal.state.vectorSize) {
case 1: mShader.append("attribute float ATTRIB_"); break;
case 2: mShader.append("attribute vec2 ATTRIB_"); break;
case 3: mShader.append("attribute vec3 ATTRIB_"); break;
@@ -211,24 +207,20 @@ bool RsdShader::loadShader(const Context *rsc) {
void RsdShader::appendUserConstants() {
for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
const Element *e = mRSProgram->mHal.state.constantTypes[ct]->getElement();
- for (uint32_t field=0; field < e->getFieldCount(); field++) {
- const Element *f = e->getField(field);
- const char *fn = e->getFieldName(field);
-
- if (fn[0] == '#') {
- continue;
- }
+ for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) {
+ const Element *f = e->mHal.state.fields[field];
+ const char *fn = e->mHal.state.fieldNames[field];
// Cannot be complex
- rsAssert(!f->getFieldCount());
- if (f->getType() == RS_TYPE_MATRIX_4X4) {
+ rsAssert(!f->mHal.state.fieldsCount);
+ if (f->mHal.state.dataType == RS_TYPE_MATRIX_4X4) {
mShader.append("uniform mat4 UNI_");
- } else if (f->getType() == RS_TYPE_MATRIX_3X3) {
+ } else if (f->mHal.state.dataType == RS_TYPE_MATRIX_3X3) {
mShader.append("uniform mat3 UNI_");
- } else if (f->getType() == RS_TYPE_MATRIX_2X2) {
+ } else if (f->mHal.state.dataType == RS_TYPE_MATRIX_2X2) {
mShader.append("uniform mat2 UNI_");
} else {
- switch (f->getComponent().getVectorSize()) {
+ switch (f->mHal.state.vectorSize) {
case 1: mShader.append("uniform float UNI_"); break;
case 2: mShader.append("uniform vec2 UNI_"); break;
case 3: mShader.append("uniform vec3 UNI_"); break;
@@ -239,8 +231,8 @@ void RsdShader::appendUserConstants() {
}
mShader.append(fn);
- if (e->getFieldArraySize(field) > 1) {
- mShader.appendFormat("[%d]", e->getFieldArraySize(field));
+ if (e->mHal.state.fieldArraySizes[field] > 1) {
+ mShader.appendFormat("[%d]", e->mHal.state.fieldArraySizes[field]);
}
mShader.append(";\n");
}
@@ -248,8 +240,8 @@ void RsdShader::appendUserConstants() {
}
void RsdShader::logUniform(const Element *field, const float *fd, uint32_t arraySize ) {
- RsDataType dataType = field->getType();
- uint32_t elementSize = field->getSizeBytes() / sizeof(float);
+ RsDataType dataType = field->mHal.state.dataType;
+ uint32_t elementSize = field->mHal.state.elementSizeBytes / sizeof(float);
for (uint32_t i = 0; i < arraySize; i ++) {
if (arraySize > 1) {
ALOGV("Array Element [%u]", i);
@@ -270,7 +262,7 @@ void RsdShader::logUniform(const Element *field, const float *fd, uint32_t array
ALOGV("{%f, %f", fd[0], fd[2]);
ALOGV(" %f, %f}", fd[1], fd[3]);
} else {
- switch (field->getComponent().getVectorSize()) {
+ switch (field->mHal.state.vectorSize) {
case 1:
ALOGV("Uniform 1 = %f", fd[0]);
break;
@@ -295,7 +287,7 @@ void RsdShader::logUniform(const Element *field, const float *fd, uint32_t array
void RsdShader::setUniform(const Context *rsc, const Element *field, const float *fd,
int32_t slot, uint32_t arraySize ) {
- RsDataType dataType = field->getType();
+ RsDataType dataType = field->mHal.state.dataType;
if (dataType == RS_TYPE_MATRIX_4X4) {
RSD_CALL_GL(glUniformMatrix4fv, slot, arraySize, GL_FALSE, fd);
} else if (dataType == RS_TYPE_MATRIX_3X3) {
@@ -303,7 +295,7 @@ void RsdShader::setUniform(const Context *rsc, const Element *field, const float
} else if (dataType == RS_TYPE_MATRIX_2X2) {
RSD_CALL_GL(glUniformMatrix2fv, slot, arraySize, GL_FALSE, fd);
} else {
- switch (field->getComponent().getVectorSize()) {
+ switch (field->mHal.state.vectorSize) {
case 1:
RSD_CALL_GL(glUniform1fv, slot, arraySize, fd);
break;
@@ -458,15 +450,11 @@ void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool
const uint8_t *data = static_cast<const uint8_t *>(alloc->getPtr());
const Element *e = mRSProgram->mHal.state.constantTypes[ct]->getElement();
- for (uint32_t field=0; field < e->getFieldCount(); field++) {
- const Element *f = e->getField(field);
- const char *fieldName = e->getFieldName(field);
- // If this field is padding, skip it
- if (fieldName[0] == '#') {
- continue;
- }
+ for (uint32_t field=0; field < e->mHal.state.fieldsCount; field++) {
+ const Element *f = e->mHal.state.fields[field];
+ const char *fieldName = e->mHal.state.fieldNames[field];
- uint32_t offset = e->getFieldOffsetBytes(field);
+ uint32_t offset = e->mHal.state.fieldOffsetBytes[field];
const float *fd = reinterpret_cast<const float *>(&data[offset]);
int32_t slot = -1;
@@ -505,7 +493,7 @@ void RsdShader::initAttribAndUniformArray() {
mAttribCount = 0;
for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) {
const Element *elem = mRSProgram->mHal.state.inputElements[ct];
- for (uint32_t field=0; field < elem->getFieldCount(); field++) {
+ for (uint32_t field=0; field < elem->mHal.state.fieldsCount; field++) {
if (elem->getFieldName(field)[0] != '#') {
mAttribCount ++;
}
@@ -515,12 +503,7 @@ void RsdShader::initAttribAndUniformArray() {
mUniformCount = 0;
for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) {
const Element *elem = mRSProgram->mHal.state.constantTypes[ct]->getElement();
-
- for (uint32_t field=0; field < elem->getFieldCount(); field++) {
- if (elem->getFieldName(field)[0] != '#') {
- mUniformCount ++;
- }
- }
+ mUniformCount += elem->mHal.state.fieldsCount;
}
mUniformCount += mRSProgram->mHal.state.texturesCount;
@@ -540,17 +523,17 @@ void RsdShader::initAttribAndUniformArray() {
void RsdShader::initAddUserElement(const Element *e, String8 *names, uint32_t *arrayLengths,
uint32_t *count, const char *prefix) {
- rsAssert(e->getFieldCount());
- for (uint32_t ct=0; ct < e->getFieldCount(); ct++) {
- const Element *ce = e->getField(ct);
- if (ce->getFieldCount()) {
+ rsAssert(e->mHal.state.fieldsCount);
+ for (uint32_t ct=0; ct < e->mHal.state.fieldsCount; ct++) {
+ const Element *ce = e->mHal.state.fields[ct];
+ if (ce->mHal.state.fieldsCount) {
initAddUserElement(ce, names, arrayLengths, count, prefix);
- } else if (e->getFieldName(ct)[0] != '#') {
+ } else {
String8 tmp(prefix);
- tmp.append(e->getFieldName(ct));
+ tmp.append(e->mHal.state.fieldNames[ct]);
names[*count].setTo(tmp.string());
if (arrayLengths) {
- arrayLengths[*count] = e->getFieldArraySize(ct);
+ arrayLengths[*count] = e->mHal.state.fieldArraySizes[ct];
}
(*count)++;
}
diff --git a/libs/rs/rsElement.h b/libs/rs/rsElement.h
index 010c612..4b6b460 100644
--- a/libs/rs/rsElement.h
+++ b/libs/rs/rsElement.h
@@ -24,7 +24,14 @@
// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-
+/*****************************************************************************
+ * CAUTION
+ *
+ * Any layout changes for this class may require a corresponding change to be
+ * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
+ * a partial copy of the information below.
+ *
+ *****************************************************************************/
// An element is a group of Components that occupies one cell in a structure.
class Element : public ObjectBase {
public:
diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h
index 84a57ca..166b5d3 100644
--- a/libs/rs/rsMesh.h
+++ b/libs/rs/rsMesh.h
@@ -23,7 +23,14 @@
// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-
+/*****************************************************************************
+ * CAUTION
+ *
+ * Any layout changes for this class may require a corresponding change to be
+ * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
+ * a partial copy of the information below.
+ *
+ *****************************************************************************/
// An element is a group of Components that occupies one cell in a structure.
class Mesh : public ObjectBase {
diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h
index 074a6b4..3878156 100644
--- a/libs/rs/rsType.h
+++ b/libs/rs/rsType.h
@@ -22,7 +22,14 @@
// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-
+/*****************************************************************************
+ * CAUTION
+ *
+ * Any layout changes for this class may require a corresponding change to be
+ * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
+ * a partial copy of the information below.
+ *
+ *****************************************************************************/
class Type : public ObjectBase {
public: