Merge "Migrate perf-critical functions away from librs."
diff --git a/driver/rsdProgram.cpp b/driver/rsdProgram.cpp
index 39b3805..27a6663 100644
--- a/driver/rsdProgram.cpp
+++ b/driver/rsdProgram.cpp
@@ -44,6 +44,9 @@
static void SyncProgramConstants(const Context *rsc, const Program *p) {
for (uint32_t ct=0; ct < p->mHal.state.texturesCount; ct++) {
const Allocation *a = p->mHal.state.textures[ct].get();
+ if (!a) {
+ continue;
+ }
DrvAllocation *drvAlloc = (DrvAllocation *)a->mHal.drv;
if (drvAlloc->uploadDeferred) {
rsdAllocationSyncAll(rsc, a, RS_ALLOCATION_USAGE_SCRIPT);
diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp
index 15cc417..90fe4b2 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -48,6 +48,7 @@
delete[] mAttribNames;
delete[] mUniformNames;
delete[] mUniformArraySizes;
+ delete[] mTextureTargets;
}
void RsdShader::initMemberVars() {
@@ -59,6 +60,7 @@
mAttribNames = NULL;
mUniformNames = NULL;
mUniformArraySizes = NULL;
+ mTextureTargets = NULL;
mIsValid = false;
}
@@ -81,6 +83,7 @@
mUniformArraySizes[uniformCount] = 1;
uniformCount++;
}
+
}
String8 RsdShader::getGLSLInputString() const {
@@ -141,8 +144,10 @@
for (uint32_t ct=0; ct < mRSProgram->mHal.state.texturesCount; ct++) {
if (mRSProgram->mHal.state.textureTargets[ct] == RS_TEXTURE_2D) {
snprintf(buf, sizeof(buf), "uniform sampler2D UNI_Tex%i;\n", ct);
+ mTextureTargets[ct] = GL_TEXTURE_2D;
} else {
snprintf(buf, sizeof(buf), "uniform samplerCube UNI_Tex%i;\n", ct);
+ mTextureTargets[ct] = GL_TEXTURE_CUBE_MAP;
}
mShader.append(buf);
}
@@ -400,9 +405,11 @@
for (uint32_t ct=0; ct < numTexturesToBind; ct++) {
glActiveTexture(GL_TEXTURE0 + ct);
+ glUniform1i(sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct);
+
if (!mRSProgram->mHal.state.textures[ct].get()) {
- LOGE("No texture bound for shader id %u, texture unit %u", (uint)this, ct);
- rsc->setError(RS_ERROR_BAD_SHADER, "No texture bound");
+ // if nothing is bound, reset to default GL texture
+ glBindTexture(mTextureTargets[ct], 0);
continue;
}
@@ -422,8 +429,6 @@
glTexParameteri(drvTex->glTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
rsdGLCheckError(rsc, "ProgramFragment::setup tex env");
}
-
- glUniform1i(sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct);
rsdGLCheckError(rsc, "ProgramFragment::setup uniforms");
}
@@ -516,6 +521,11 @@
mUniformNames = new String8[mUniformCount];
mUniformArraySizes = new uint32_t[mUniformCount];
}
+
+ mTextureCount = mRSProgram->mHal.state.texturesCount;
+ if (mTextureCount) {
+ mTextureTargets = new uint32_t[mTextureCount];
+ }
}
void RsdShader::initAddUserElement(const Element *e, String8 *names, uint32_t *arrayLengths, uint32_t *count, const char *prefix) {
diff --git a/driver/rsdShader.h b/driver/rsdShader.h
index 63c4231..3f0d6ea 100644
--- a/driver/rsdShader.h
+++ b/driver/rsdShader.h
@@ -84,6 +84,7 @@
uint32_t mType;
uint32_t mTextureCount;
+ uint32_t *mTextureTargets;
uint32_t mAttribCount;
uint32_t mUniformCount;
android::String8 *mAttribNames;
diff --git a/scriptc/rs_core.rsh b/scriptc/rs_core.rsh
index d939fb3..1583090 100644
--- a/scriptc/rs_core.rsh
+++ b/scriptc/rs_core.rsh
@@ -1,3 +1,9 @@
+/** @file rs_core.rsh
+ * \brief todo-jsams
+ *
+ * todo-jsams
+ *
+ */
#ifndef __RS_CORE_RSH__
#define __RS_CORE_RSH__
@@ -165,8 +171,14 @@
*/
_RS_RUNTIME void __attribute__((overloadable))
rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
+/**
+ * \overload
+ */
_RS_RUNTIME void __attribute__((overloadable))
rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
+/**
+ * \overload
+ */
_RS_RUNTIME void __attribute__((overloadable))
rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
@@ -181,8 +193,14 @@
*/
_RS_RUNTIME float __attribute__((overloadable))
rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
+/**
+ * \overload
+ */
_RS_RUNTIME float __attribute__((overloadable))
rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
+/**
+ * \overload
+ */
_RS_RUNTIME float __attribute__((overloadable))
rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
@@ -192,7 +210,13 @@
* @param m
*/
extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix4x4 *m);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix3x3 *m);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix2x2 *m);
/**
@@ -201,18 +225,36 @@
* @param m
*/
extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const float *v);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const float *v);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const float *v);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *v);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v);
/**
* Set the elements of a matrix from another matrix.
*
* @param m
*/
-extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *v);
-extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v);
extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix2x2 *v);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const rs_matrix3x3 *v);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const rs_matrix2x2 *v);
/**
@@ -227,97 +269,258 @@
extern void __attribute__((overloadable))
rsMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
+/**
+ * Load a scale matrix.
+ *
+ * @param m
+ * @param x
+ * @param y
+ * @param z
+ */
extern void __attribute__((overloadable))
rsMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
+/**
+ * Load a translation matrix.
+ *
+ * @param m
+ * @param x
+ * @param y
+ * @param z
+ */
extern void __attribute__((overloadable))
rsMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
+/**
+ * Multiply two matrix (lhs, rhs) and place the result in m.
+ *
+ * @param m
+ * @param lhs
+ * @param rhs
+ */
extern void __attribute__((overloadable))
rsMatrixLoadMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
-
-extern void __attribute__((overloadable))
-rsMatrixMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
-
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsMatrixLoadMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs);
-
-extern void __attribute__((overloadable))
-rsMatrixMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
-
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsMatrixLoadMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs);
+/**
+ * Multiply the matrix m by rhs and place the result back into m.
+ *
+ * @param m (lhs)
+ * @param rhs
+ */
+extern void __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+rsMatrixMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsMatrixMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
+/**
+ * Multiple matrix m with a rotation matrix
+ *
+ * @param m
+ * @param rot
+ * @param x
+ * @param y
+ * @param z
+ */
extern void __attribute__((overloadable))
rsMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
+/**
+ * Multiple matrix m with a scale matrix
+ *
+ * @param m
+ * @param x
+ * @param y
+ * @param z
+ */
extern void __attribute__((overloadable))
rsMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
+/**
+ * Multiple matrix m with a translation matrix
+ *
+ * @param m
+ * @param x
+ * @param y
+ * @param z
+ */
extern void __attribute__((overloadable))
rsMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
+/**
+ * Load an Ortho projection matrix constructed from the 6 planes
+ *
+ * @param m
+ * @param left
+ * @param right
+ * @param bottom
+ * @param top
+ * @param near
+ * @param far
+ */
extern void __attribute__((overloadable))
rsMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far);
+/**
+ * Load an Frustum projection matrix constructed from the 6 planes
+ *
+ * @param m
+ * @param left
+ * @param right
+ * @param bottom
+ * @param top
+ * @param near
+ * @param far
+ */
extern void __attribute__((overloadable))
rsMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far);
+/**
+ * Load an perspective projection matrix constructed from the 6 planes
+ *
+ * @param m
+ * @param fovy Field of view, in degrees along the Y axis.
+ * @param aspect Ratio of x / y.
+ * @param near
+ * @param far
+ */
extern void __attribute__((overloadable))
rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
#if !defined(RS_VERSION) || (RS_VERSION < 14)
+/**
+ * Multiply a vector by a matrix and return the result vector.
+ * API version 10-13
+ */
_RS_RUNTIME float4 __attribute__((overloadable))
rsMatrixMultiply(rs_matrix4x4 *m, float4 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float4 __attribute__((overloadable))
rsMatrixMultiply(rs_matrix4x4 *m, float3 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float4 __attribute__((overloadable))
rsMatrixMultiply(rs_matrix4x4 *m, float2 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float3 __attribute__((overloadable))
rsMatrixMultiply(rs_matrix3x3 *m, float3 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float3 __attribute__((overloadable))
rsMatrixMultiply(rs_matrix3x3 *m, float2 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float2 __attribute__((overloadable))
rsMatrixMultiply(rs_matrix2x2 *m, float2 in);
#else
+/**
+ * Multiply a vector by a matrix and return the result vector.
+ * API version 10-13
+ */
_RS_RUNTIME float4 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix4x4 *m, float4 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float4 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix4x4 *m, float3 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float4 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix4x4 *m, float2 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float3 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix3x3 *m, float3 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float3 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix3x3 *m, float2 in);
+/**
+ * \overload
+ */
_RS_RUNTIME float2 __attribute__((overloadable))
rsMatrixMultiply(const rs_matrix2x2 *m, float2 in);
#endif
-// Returns true if the matrix was successfully inversed
+
+/**
+ * Returns true if the matrix was successfully inversed
+ *
+ * @param m
+ */
extern bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m);
+
+/**
+ * Returns true if the matrix was successfully inversed and transposed.
+ *
+ * @param m
+ */
extern bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m);
+
+/**
+ * Transpose the matrix m.
+ *
+ * @param m
+ */
extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m);
/////////////////////////////////////////////////////
// quaternion ops
/////////////////////////////////////////////////////
+/**
+ * Set the quaternion components
+ * @param w component
+ * @param x component
+ * @param y component
+ * @param z component
+ */
static void __attribute__((overloadable))
rsQuaternionSet(rs_quaternion *q, float w, float x, float y, float z) {
q->w = w;
@@ -326,6 +529,11 @@
q->z = z;
}
+/**
+ * Set the quaternion from another quaternion
+ * @param q destination quaternion
+ * @param rhs source quaternion
+ */
static void __attribute__((overloadable))
rsQuaternionSet(rs_quaternion *q, const rs_quaternion *rhs) {
q->w = rhs->w;
@@ -334,6 +542,11 @@
q->z = rhs->z;
}
+/**
+ * Multiply quaternion by a scalar
+ * @param q quaternion to multiply
+ * @param s scalar
+ */
static void __attribute__((overloadable))
rsQuaternionMultiply(rs_quaternion *q, float s) {
q->w *= s;
@@ -342,6 +555,11 @@
q->z *= s;
}
+/**
+ * Multiply quaternion by another quaternion
+ * @param q destination quaternion
+ * @param rhs right hand side quaternion to multiply by
+ */
static void __attribute__((overloadable))
rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) {
q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w;
@@ -350,6 +568,11 @@
q->z = q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z;
}
+/**
+ * Add two quaternions
+ * @param q destination quaternion to add to
+ * @param rsh right hand side quaternion to add
+ */
static void
rsQuaternionAdd(rs_quaternion *q, const rs_quaternion *rhs) {
q->w *= rhs->w;
@@ -358,6 +581,14 @@
q->z *= rhs->z;
}
+/**
+ * Loads a quaternion that represents a rotation about an arbitrary unit vector
+ * @param q quaternion to set
+ * @param rot angle to rotate by
+ * @param x component of a vector
+ * @param y component of a vector
+ * @param x component of a vector
+ */
static void
rsQuaternionLoadRotateUnit(rs_quaternion *q, float rot, float x, float y, float z) {
rot *= (float)(M_PI / 180.0f) * 0.5f;
@@ -370,6 +601,15 @@
q->z = z * s;
}
+/**
+ * Loads a quaternion that represents a rotation about an arbitrary vector
+ * (doesn't have to be unit)
+ * @param q quaternion to set
+ * @param rot angle to rotate by
+ * @param x component of a vector
+ * @param y component of a vector
+ * @param x component of a vector
+ */
static void
rsQuaternionLoadRotate(rs_quaternion *q, float rot, float x, float y, float z) {
const float len = x*x + y*y + z*z;
@@ -382,6 +622,10 @@
rsQuaternionLoadRotateUnit(q, rot, x, y, z);
}
+/**
+ * Conjugates the quaternion
+ * @param q quaternion to conjugate
+ */
static void
rsQuaternionConjugate(rs_quaternion *q) {
q->x = -q->x;
@@ -389,11 +633,21 @@
q->z = -q->z;
}
+/**
+ * Dot product of two quaternions
+ * @param q0 first quaternion
+ * @param q1 second quaternion
+ * @return dot product between q0 and q1
+ */
static float
rsQuaternionDot(const rs_quaternion *q0, const rs_quaternion *q1) {
return q0->w*q1->w + q0->x*q1->x + q0->y*q1->y + q0->z*q1->z;
}
+/**
+ * Normalizes the quaternion
+ * @param q quaternion to normalize
+ */
static void
rsQuaternionNormalize(rs_quaternion *q) {
const float len = rsQuaternionDot(q, q);
@@ -403,6 +657,13 @@
}
}
+/**
+ * Performs spherical linear interpolation between two quaternions
+ * @param q result quaternion from interpolation
+ * @param q0 first param
+ * @param q1 second param
+ * @param t how much to interpolate by
+ */
static void
rsQuaternionSlerp(rs_quaternion *q, const rs_quaternion *q0, const rs_quaternion *q1, float t) {
if (t <= 0.0f) {
@@ -445,6 +706,11 @@
tempq0.y*scale + tempq1.y*invScale, tempq0.z*scale + tempq1.z*invScale);
}
+/**
+ * Computes rotation matrix from the normalized quaternion
+ * @param m resulting matrix
+ * @param p normalized quaternion
+ */
static void rsQuaternionGetMatrixUnit(rs_matrix4x4 *m, const rs_quaternion *q) {
float x2 = 2.0f * q->x * q->x;
float y2 = 2.0f * q->y * q->y;
@@ -480,41 +746,52 @@
/////////////////////////////////////////////////////
// utility funcs
/////////////////////////////////////////////////////
+
+/**
+ * Computes 6 frustum planes from the view projection matrix
+ * @param viewProj matrix to extract planes from
+ * @param left plane
+ * @param right plane
+ * @param top plane
+ * @param bottom plane
+ * @param near plane
+ * @param far plane
+ */
__inline__ static void __attribute__((overloadable, always_inline))
-rsExtractFrustumPlanes(const rs_matrix4x4 *modelViewProj,
+rsExtractFrustumPlanes(const rs_matrix4x4 *viewProj,
float4 *left, float4 *right,
float4 *top, float4 *bottom,
float4 *near, float4 *far) {
// x y z w = a b c d in the plane equation
- left->x = modelViewProj->m[3] + modelViewProj->m[0];
- left->y = modelViewProj->m[7] + modelViewProj->m[4];
- left->z = modelViewProj->m[11] + modelViewProj->m[8];
- left->w = modelViewProj->m[15] + modelViewProj->m[12];
+ left->x = viewProj->m[3] + viewProj->m[0];
+ left->y = viewProj->m[7] + viewProj->m[4];
+ left->z = viewProj->m[11] + viewProj->m[8];
+ left->w = viewProj->m[15] + viewProj->m[12];
- right->x = modelViewProj->m[3] - modelViewProj->m[0];
- right->y = modelViewProj->m[7] - modelViewProj->m[4];
- right->z = modelViewProj->m[11] - modelViewProj->m[8];
- right->w = modelViewProj->m[15] - modelViewProj->m[12];
+ right->x = viewProj->m[3] - viewProj->m[0];
+ right->y = viewProj->m[7] - viewProj->m[4];
+ right->z = viewProj->m[11] - viewProj->m[8];
+ right->w = viewProj->m[15] - viewProj->m[12];
- top->x = modelViewProj->m[3] - modelViewProj->m[1];
- top->y = modelViewProj->m[7] - modelViewProj->m[5];
- top->z = modelViewProj->m[11] - modelViewProj->m[9];
- top->w = modelViewProj->m[15] - modelViewProj->m[13];
+ top->x = viewProj->m[3] - viewProj->m[1];
+ top->y = viewProj->m[7] - viewProj->m[5];
+ top->z = viewProj->m[11] - viewProj->m[9];
+ top->w = viewProj->m[15] - viewProj->m[13];
- bottom->x = modelViewProj->m[3] + modelViewProj->m[1];
- bottom->y = modelViewProj->m[7] + modelViewProj->m[5];
- bottom->z = modelViewProj->m[11] + modelViewProj->m[9];
- bottom->w = modelViewProj->m[15] + modelViewProj->m[13];
+ bottom->x = viewProj->m[3] + viewProj->m[1];
+ bottom->y = viewProj->m[7] + viewProj->m[5];
+ bottom->z = viewProj->m[11] + viewProj->m[9];
+ bottom->w = viewProj->m[15] + viewProj->m[13];
- near->x = modelViewProj->m[3] + modelViewProj->m[2];
- near->y = modelViewProj->m[7] + modelViewProj->m[6];
- near->z = modelViewProj->m[11] + modelViewProj->m[10];
- near->w = modelViewProj->m[15] + modelViewProj->m[14];
+ near->x = viewProj->m[3] + viewProj->m[2];
+ near->y = viewProj->m[7] + viewProj->m[6];
+ near->z = viewProj->m[11] + viewProj->m[10];
+ near->w = viewProj->m[15] + viewProj->m[14];
- far->x = modelViewProj->m[3] - modelViewProj->m[2];
- far->y = modelViewProj->m[7] - modelViewProj->m[6];
- far->z = modelViewProj->m[11] - modelViewProj->m[10];
- far->w = modelViewProj->m[15] - modelViewProj->m[14];
+ far->x = viewProj->m[3] - viewProj->m[2];
+ far->y = viewProj->m[7] - viewProj->m[6];
+ far->z = viewProj->m[11] - viewProj->m[10];
+ far->w = viewProj->m[15] - viewProj->m[14];
float len = length(left->xyz);
*left /= len;
@@ -530,6 +807,16 @@
*far /= len;
}
+/**
+ * Checks if a sphere is withing the 6 frustum planes
+ * @param sphere float4 representing the sphere
+ * @param left plane
+ * @param right plane
+ * @param top plane
+ * @param bottom plane
+ * @param near plane
+ * @param far plane
+ */
__inline__ static bool __attribute__((overloadable, always_inline))
rsIsSphereInFrustum(float4 *sphere,
float4 *left, float4 *right,
@@ -568,11 +855,34 @@
// int ops
/////////////////////////////////////////////////////
+/**
+ * Clamp the value amount between low and high.
+ *
+ * @param amount The value to clamp
+ * @param low
+ * @param high
+ */
_RS_RUNTIME uint __attribute__((overloadable, always_inline)) rsClamp(uint amount, uint low, uint high);
+
+/**
+ * \overload
+ */
_RS_RUNTIME int __attribute__((overloadable, always_inline)) rsClamp(int amount, int low, int high);
+/**
+ * \overload
+ */
_RS_RUNTIME ushort __attribute__((overloadable, always_inline)) rsClamp(ushort amount, ushort low, ushort high);
+/**
+ * \overload
+ */
_RS_RUNTIME short __attribute__((overloadable, always_inline)) rsClamp(short amount, short low, short high);
+/**
+ * \overload
+ */
_RS_RUNTIME uchar __attribute__((overloadable, always_inline)) rsClamp(uchar amount, uchar low, uchar high);
+/**
+ * \overload
+ */
_RS_RUNTIME char __attribute__((overloadable, always_inline)) rsClamp(char amount, char low, char high);
#undef _RS_RUNTIME
diff --git a/scriptc/rs_math.rsh b/scriptc/rs_math.rsh
index 1d36cc6..e44c051 100644
--- a/scriptc/rs_math.rsh
+++ b/scriptc/rs_math.rsh
@@ -1,6 +1,44 @@
+/** @file rs_math.rsh
+ * \brief todo-jsams
+ *
+ * todo-jsams
+ *
+ */
#ifndef __RS_MATH_RSH__
#define __RS_MATH_RSH__
+
+
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsSetObject(rs_element *dst, rs_element src);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsSetObject(rs_type *dst, rs_type src);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsSetObject(rs_allocation *dst, rs_allocation src);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsSetObject(rs_sampler *dst, rs_sampler src);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsSetObject(rs_script *dst, rs_script src);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsSetObject(rs_mesh *dst, rs_mesh src);
/**
* Copy reference to the specified object.
*
@@ -8,25 +46,25 @@
* @param src
*/
extern void __attribute__((overloadable))
- rsSetObject(rs_element *dst, rs_element src);
-extern void __attribute__((overloadable))
- rsSetObject(rs_type *dst, rs_type src);
-extern void __attribute__((overloadable))
- rsSetObject(rs_allocation *dst, rs_allocation src);
-extern void __attribute__((overloadable))
- rsSetObject(rs_sampler *dst, rs_sampler src);
-extern void __attribute__((overloadable))
- rsSetObject(rs_script *dst, rs_script src);
-extern void __attribute__((overloadable))
- rsSetObject(rs_mesh *dst, rs_mesh src);
-extern void __attribute__((overloadable))
rsSetObject(rs_program_fragment *dst, rs_program_fragment src);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsSetObject(rs_program_vertex *dst, rs_program_vertex src);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsSetObject(rs_program_raster *dst, rs_program_raster src);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsSetObject(rs_program_store *dst, rs_program_store src);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsSetObject(rs_font *dst, rs_font src);
@@ -37,53 +75,114 @@
*/
extern void __attribute__((overloadable))
rsClearObject(rs_element *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_type *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_allocation *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_sampler *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_script *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_mesh *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_program_fragment *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_program_vertex *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_program_raster *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_program_store *dst);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsClearObject(rs_font *dst);
/**
+ * \overload
+ */
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_element);
+/**
+ * \overload
+ */
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_type);
+/**
+ * \overload
+ */
+extern bool __attribute__((overloadable))
+ rsIsObject(rs_allocation);
+/**
* Tests if the object is valid. Returns true if the object is valid, false if
* it is NULL.
*
* @return bool
*/
-extern bool __attribute__((overloadable))
- rsIsObject(rs_element);
-extern bool __attribute__((overloadable))
- rsIsObject(rs_type);
-extern bool __attribute__((overloadable))
- rsIsObject(rs_allocation);
+
extern bool __attribute__((overloadable))
rsIsObject(rs_sampler);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_script);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_mesh);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_program_fragment);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_program_vertex);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_program_raster);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_program_store);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsIsObject(rs_font);
@@ -188,46 +287,82 @@
uint32_t srcMip,
rs_allocation_cubemap_face srcFace);
-// Extract a single element from an allocation.
+
+/**
+ * Extract a single element from an allocation.
+ */
extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation, uint32_t x);
+/**
+ * \overload
+ */
extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation, uint32_t x, uint32_t y);
+/**
+ * \overload
+ */
extern const void * __attribute__((overloadable))
rsGetElementAt(rs_allocation, uint32_t x, uint32_t y, uint32_t z);
-// Return a random value between 0 (or min_value) and max_malue.
+/**
+ * Return a random value between 0 (or min_value) and max_malue.
+ */
extern int __attribute__((overloadable))
rsRand(int max_value);
+/**
+ * \overload
+ */
extern int __attribute__((overloadable))
rsRand(int min_value, int max_value);
+/**
+ * \overload
+ */
extern float __attribute__((overloadable))
rsRand(float max_value);
+/**
+ * \overload
+ */
extern float __attribute__((overloadable))
rsRand(float min_value, float max_value);
-// return the fractional part of a float
-// min(v - ((int)floor(v)), 0x1.fffffep-1f);
+/**
+ * Returns the fractional part of a float
+ */
extern float __attribute__((overloadable))
rsFrac(float);
-// Send a message back to the client. Will not block and returns true
-// if the message was sendable and false if the fifo was full.
-// A message ID is required. Data payload is optional.
+/**
+ * Send a message back to the client. Will not block and returns true
+ * if the message was sendable and false if the fifo was full.
+ * A message ID is required. Data payload is optional.
+ */
extern bool __attribute__((overloadable))
rsSendToClient(int cmdID);
+/**
+ * \overload
+ */
extern bool __attribute__((overloadable))
rsSendToClient(int cmdID, const void *data, uint len);
-
-// Send a message back to the client, blocking until the message is queued.
-// A message ID is required. Data payload is optional.
+/**
+ * Send a message back to the client, blocking until the message is queued.
+ * A message ID is required. Data payload is optional.
+ */
extern void __attribute__((overloadable))
rsSendToClientBlocking(int cmdID);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsSendToClientBlocking(int cmdID, const void *data, uint len);
-// Script to Script
+/**
+ * Launch order hint for rsForEach calls. This provides a hint to the system to
+ * determine in which order the root function of the target is called with each
+ * cell of the allocation.
+ *
+ * This is a hint and implementations may not obey the order.
+ */
enum rs_for_each_strategy {
RS_FOR_EACH_STRATEGY_SERIAL,
RS_FOR_EACH_STRATEGY_DONT_CARE,
@@ -237,6 +372,11 @@
RS_FOR_EACH_STRATEGY_TILE_LARGE
};
+
+/**
+ * Structure to provide extra information to a rsForEach call. Primarly used to
+ * restrict the call to a subset of cells in the allocation.
+ */
typedef struct rs_script_call {
enum rs_for_each_strategy strategy;
uint32_t xStart;
@@ -249,26 +389,67 @@
uint32_t arrayEnd;
} rs_script_call_t;
+/**
+ * Make a script to script call to launch work. One of the input or output is
+ * required to be a valid object. The input and output must be of the same
+ * dimensions.
+ * API 10-13
+ *
+ * @param script The target script to call
+ * @param input The allocation to source data from
+ * @param output the allocation to write date into
+ * @param usrData The user definied params to pass to the root script. May be
+ * NULL.
+ * @param sc Extra control infomation used to select a sub-region of the
+ * allocation to be processed or suggest a walking strategy. May be
+ * NULL.
+ *
+ * */
#if !defined(RS_VERSION) || (RS_VERSION < 14)
extern void __attribute__((overloadable))
- rsForEach(rs_script script, rs_allocation input,
+ rsForEach(rs_script script script, rs_allocation input,
rs_allocation output, const void * usrData,
- const rs_script_call_t *);
-
+ const rs_script_call_t *sc);
+/**
+ * \overload
+ */
extern void __attribute__((overloadable))
rsForEach(rs_script script, rs_allocation input,
rs_allocation output, const void * usrData);
#else
-extern void __attribute__((overloadable))
- rsForEach(rs_script script, rs_allocation input, rs_allocation output);
-extern void __attribute__((overloadable))
- rsForEach(rs_script script, rs_allocation input, rs_allocation output,
- const void * usrData, size_t usrDataLen);
-
+/**
+ * Make a script to script call to launch work. One of the input or output is
+ * required to be a valid object. The input and output must be of the same
+ * dimensions.
+ * API 14+
+ *
+ * @param script The target script to call
+ * @param input The allocation to source data from
+ * @param output the allocation to write date into
+ * @param usrData The user definied params to pass to the root script. May be
+ * NULL.
+ * @param usrDataLen The size of the userData structure. This will be used to
+ * perform a shallow copy of the data if necessary.
+ * @param sc Extra control infomation used to select a sub-region of the
+ * allocation to be processed or suggest a walking strategy. May be
+ * NULL.
+ *
+ */
extern void __attribute__((overloadable))
rsForEach(rs_script script, rs_allocation input, rs_allocation output,
const void * usrData, size_t usrDataLen, const rs_script_call_t *);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input, rs_allocation output,
+ const void * usrData, size_t usrDataLen);
+/**
+ * \overload
+ */
+extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input, rs_allocation output);
#endif
diff --git a/scriptc/rs_types.rsh b/scriptc/rs_types.rsh
index 121e013..9a79f5e 100644
--- a/scriptc/rs_types.rsh
+++ b/scriptc/rs_types.rsh
@@ -1,98 +1,361 @@
+/** @file rs_time.rsh
+ *
+ * Define the standard Renderscript types
+ *
+ * Integers
+ * 8 bit: char, int8_t
+ * 16 bit: short, int16_t
+ * 32 bit: int, in32_t
+ * 64 bit: long, long long, int64_t
+ *
+ * Unsigned Integers
+ * 8 bit: uchar, uint8_t
+ * 16 bit: ushort, uint16_t
+ * 32 bit: uint, uint32_t
+ * 64 bit: ulong, uint64_t
+ *
+ * Floating point
+ * 32 bit: float
+ * 64 bit: double
+ *
+ * Vectors of length 2, 3, and 4 are supported for all the types above.
+ *
+ */
+
#ifndef __RS_TYPES_RSH__
#define __RS_TYPES_RSH__
#define M_PI 3.14159265358979323846264338327950288f /* pi */
#include "stdbool.h"
+/**
+ * 8 bit integer type
+ */
typedef char int8_t;
+/**
+ * 16 bit integer type
+ */
typedef short int16_t;
+/**
+ * 32 bit integer type
+ */
typedef int int32_t;
+/**
+ * 64 bit integer type
+ */
typedef long long int64_t;
-
+/**
+ * 8 bit unsigned integer type
+ */
typedef unsigned char uint8_t;
+/**
+ * 16 bit unsigned integer type
+ */
typedef unsigned short uint16_t;
+/**
+ * 32 bit unsigned integer type
+ */
typedef unsigned int uint32_t;
+/**
+ * 64 bit unsigned integer type
+ */
typedef unsigned long long uint64_t;
-
+/**
+ * 8 bit unsigned integer type
+ */
typedef uint8_t uchar;
+/**
+ * 16 bit unsigned integer type
+ */
typedef uint16_t ushort;
+/**
+ * 32 bit unsigned integer type
+ */
typedef uint32_t uint;
+/**
+ * Typedef for unsigned char (use for 64-bit unsigned integers)
+ */
typedef uint64_t ulong;
-
+/**
+ * Typedef for unsigned int
+ */
typedef uint32_t size_t;
+/**
+ * Typedef for int (use for 32-bit integers)
+ */
typedef int32_t ssize_t;
+/**
+ * \brief Opaque handle to a RenderScript element.
+ *
+ * See: android.renderscript.Element
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_element;
+/**
+ * \brief Opaque handle to a RenderScript type.
+ *
+ * See: android.renderscript.Type
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_type;
+/**
+ * \brief Opaque handle to a RenderScript allocation.
+ *
+ * See: android.renderscript.Allocation
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_allocation;
+/**
+ * \brief Opaque handle to a RenderScript sampler object.
+ *
+ * See: android.renderscript.Sampler
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_sampler;
+/**
+ * \brief Opaque handle to a RenderScript script object.
+ *
+ * See: android.renderscript.ScriptC
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_script;
+/**
+ * \brief Opaque handle to a RenderScript mesh object.
+ *
+ * See: android.renderscript.Mesh
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_mesh;
+/**
+ * \brief Opaque handle to a RenderScript ProgramFragment object.
+ *
+ * See: android.renderscript.ProgramFragment
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_fragment;
+/**
+ * \brief Opaque handle to a RenderScript ProgramVertex object.
+ *
+ * See: android.renderscript.ProgramVertex
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_vertex;
+/**
+ * \brief Opaque handle to a RenderScript sampler object.
+ *
+ * See: android.renderscript.Sampler
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_raster;
+/**
+ * \brief Opaque handle to a RenderScript ProgramStore object.
+ *
+ * See: android.renderscript.ProgramStore
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_store;
+/**
+ * \brief Opaque handle to a RenderScript font object.
+ *
+ * See: android.renderscript.Font
+ */
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_font;
-
+/**
+ * Vector version of the basic float type.
+ * Provides two float fields packed into a single 64bit field with 64 bit
+ * alignment.
+ */
typedef float float2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic float type. Provides three float fields packed
+ * into a single 128bit field with 128 bit alignment.
+ */
typedef float float3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic float type.
+ * Provides four float fields packed into a single 128bit field with 128bit
+ * alignment.
+ */
typedef float float4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic double type. Provides two double fields packed
+ * into a single 128bit field with 128bit alignment.
+ */
typedef double double2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic double type. Provides three double fields packed
+ * into a single 256bit field with 256bit alignment.
+ */
typedef double double3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic double type. Provides four double fields packed
+ * into a single 256bit field with 256bit alignment.
+ */
typedef double double4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic uchar type. Provides two uchar fields packed
+ * into a single 16bit field with 16bit alignment.
+ */
typedef uchar uchar2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic uchar type. Provides three uchar fields packed
+ * into a single 32bit field with 32bit alignment.
+ */
typedef uchar uchar3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic uchar type. Provides four uchar fields packed
+ * into a single 32bit field with 32bit alignment.
+ */
typedef uchar uchar4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic ushort type. Provides two ushort fields packed
+ * into a single 32bit field with 32bit alignment.
+ */
typedef ushort ushort2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic ushort type. Provides three ushort fields packed
+ * into a single 64bit field with 64bit alignment.
+ */
typedef ushort ushort3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic ushort type. Provides four ushort fields packed
+ * into a single 64bit field with 64bit alignment.
+ */
typedef ushort ushort4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic uint type. Provides two uint fields packed into a
+ * single 64bit field with 64bit alignment.
+ */
typedef uint uint2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic uint type. Provides three uint fields packed into
+ * a single 128bit field with 128bit alignment.
+ */
typedef uint uint3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic uint type. Provides four uint fields packed into
+ * a single 128bit field with 128bit alignment.
+ */
typedef uint uint4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic ulong type. Provides two ulong fields packed into
+ * a single 128bit field with 128bit alignment.
+ */
typedef ulong ulong2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic ulong type. Provides three ulong fields packed
+ * into a single 256bit field with 256bit alignment.
+ */
typedef ulong ulong3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic ulong type. Provides four ulong fields packed
+ * into a single 256bit field with 256bit alignment.
+ */
typedef ulong ulong4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic char type. Provides two char fields packed into a
+ * single 16bit field with 16bit alignment.
+ */
typedef char char2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic char type. Provides three char fields packed into
+ * a single 32bit field with 32bit alignment.
+ */
typedef char char3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic char type. Provides four char fields packed into
+ * a single 32bit field with 32bit alignment.
+ */
typedef char char4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic short type. Provides two short fields packed into
+ * a single 32bit field with 32bit alignment.
+ */
typedef short short2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic short type. Provides three short fields packed
+ * into a single 64bit field with 64bit alignment.
+ */
typedef short short3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic short type. Provides four short fields packed
+ * into a single 64bit field with 64bit alignment.
+ */
typedef short short4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic int type. Provides two int fields packed into a
+ * single 64bit field with 64bit alignment.
+ */
typedef int int2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic int type. Provides three int fields packed into a
+ * single 128bit field with 128bit alignment.
+ */
typedef int int3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic int type. Provides two four fields packed into a
+ * single 128bit field with 128bit alignment.
+ */
typedef int int4 __attribute__((ext_vector_type(4)));
+/**
+ * Vector version of the basic long type. Provides two long fields packed into a
+ * single 128bit field with 128bit alignment.
+ */
typedef long long2 __attribute__((ext_vector_type(2)));
+/**
+ * Vector version of the basic long type. Provides three long fields packed into
+ * a single 256bit field with 256bit alignment.
+ */
typedef long long3 __attribute__((ext_vector_type(3)));
+/**
+ * Vector version of the basic long type. Provides four long fields packed into
+ * a single 256bit field with 256bit alignment.
+ */
typedef long long4 __attribute__((ext_vector_type(4)));
+/**
+ * \brief 4x4 float matrix
+ *
+ * Native holder for RS matrix. Elements are stored in the array at the
+ * location [row*4 + col]
+ */
typedef struct {
float m[16];
} rs_matrix4x4;
-
+/**
+ * \brief 3x3 float matrix
+ *
+ * Native holder for RS matrix. Elements are stored in the array at the
+ * location [row*3 + col]
+ */
typedef struct {
float m[9];
} rs_matrix3x3;
-
+/**
+ * \brief 2x2 float matrix
+ *
+ * Native holder for RS matrix. Elements are stored in the array at the
+ * location [row*2 + col]
+ */
typedef struct {
float m[4];
} rs_matrix2x2;
+/**
+ * quaternion type for use with the quaternion functions
+ */
typedef float4 rs_quaternion;
#define RS_PACKED __attribute__((packed, aligned(4)))
-
#define NULL ((const void *)0)
+
+/**
+ * \brief Enum for selecting cube map faces
+ *
+ * Used todo-alexst
+ */
typedef enum {
RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
@@ -102,6 +365,12 @@
RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
} rs_allocation_cubemap_face;
+/**
+ * \brief Bitfield to specify the usage types for an allocation.
+ *
+ * These values are ORed together to specify which usages or memory spaces are
+ * relevant to an allocation or an operation on an allocation.
+ */
typedef enum {
RS_ALLOCATION_USAGE_SCRIPT = 0x0001,
RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,