summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gross <dgross@google.com>2015-03-17 11:09:20 -0700
committerDavid Gross <dgross@google.com>2015-03-17 11:09:20 -0700
commit6a3c8f33e4a334ad6a14e5b0a4d469286a6d3282 (patch)
tree2626fa621e6411fd2cf871024fa2ec126b082ec0
parent2ff43385c8563ecf8d81a421324ffff60930052a (diff)
downloadrs-6a3c8f33e4a334ad6a14e5b0a4d469286a6d3282.tar.gz
Add remaining new kernel invocation context query APIs rsGet*().
Bug: 18964628 Change-Id: I067eb3a7672d79f308d4c0919a7aa6cddccd0bd6
-rw-r--r--driver/runtime/rs_core.c48
-rw-r--r--java/tests/RsTest/src/com/android/rs/test/RSTestCore.java1
-rw-r--r--java/tests/RsTest/src/com/android/rs/test/UT_ctxt_default.java60
-rw-r--r--java/tests/RsTest/src/com/android/rs/test/ctxt_default.rs68
-rw-r--r--scriptc/rs_core.rsh83
5 files changed, 260 insertions, 0 deletions
diff --git a/driver/runtime/rs_core.c b/driver/runtime/rs_core.c
index de3364ef..856c42bf 100644
--- a/driver/runtime/rs_core.c
+++ b/driver/runtime/rs_core.c
@@ -177,6 +177,30 @@ extern int __attribute__((overloadable)) rsRand(int min, int max) {
return (int)rsRand((float)min, (float)max);
}
+extern uint32_t __attribute__((overloadable)) rsGetArray0(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->current.array[0];
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetArray1(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->current.array[1];
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetArray2(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->current.array[2];
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetArray3(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->current.array[3];
+}
+
+extern rs_allocation_cubemap_face __attribute__((overloadable)) rsGetFace(rs_kernel_context ctxt) {
+ return (rs_allocation_cubemap_face)(((struct RsExpandKernelDriverInfo *)ctxt)->current.face);
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetLod(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->current.lod;
+}
+
extern uint32_t __attribute__((overloadable)) rsGetDimX(rs_kernel_context ctxt) {
return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.x;
}
@@ -189,6 +213,30 @@ extern uint32_t __attribute__((overloadable)) rsGetDimZ(rs_kernel_context ctxt)
return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.z;
}
+extern uint32_t __attribute__((overloadable)) rsGetDimArray0(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.array[0];
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetDimArray1(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.array[1];
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetDimArray2(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.array[2];
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetDimArray3(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.array[3];
+}
+
+extern bool __attribute__((overloadable)) rsGetDimHasFaces(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.face != 0;
+}
+
+extern uint32_t __attribute__((overloadable)) rsGetDimLod(rs_kernel_context ctxt) {
+ return ((struct RsExpandKernelDriverInfo *)ctxt)->dim.lod;
+}
+
#define PRIM_DEBUG(T) \
extern void __attribute__((overloadable)) rsDebug(const char *, const T *); \
void __attribute__((overloadable)) rsDebug(const char *txt, T val) { \
diff --git a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
index 63a722fd..e2de83ac 100644
--- a/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
+++ b/java/tests/RsTest/src/com/android/rs/test/RSTestCore.java
@@ -68,6 +68,7 @@ public class RSTestCore {
unitTests.add(new UT_kernel2d(this, mRes, mCtx));
// unitTests.add(new UT_kernel3d(this, mRes, mCtx)); // does not pass reliably yet
unitTests.add(new UT_kernel2d_oldstyle(this, mRes, mCtx));
+ unitTests.add(new UT_ctxt_default(this, mRes, mCtx));
unitTests.add(new UT_bug_char(this, mRes, mCtx));
unitTests.add(new UT_clamp(this, mRes, mCtx));
unitTests.add(new UT_clamp_relaxed(this, mRes, mCtx));
diff --git a/java/tests/RsTest/src/com/android/rs/test/UT_ctxt_default.java b/java/tests/RsTest/src/com/android/rs/test/UT_ctxt_default.java
new file mode 100644
index 00000000..9993ca4f
--- /dev/null
+++ b/java/tests/RsTest/src/com/android/rs/test/UT_ctxt_default.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 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.rs.test;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+public class UT_ctxt_default extends UnitTest {
+ private Resources mRes;
+ private Allocation A;
+ private Allocation B;
+
+ protected UT_ctxt_default(RSTestCore rstc, Resources res, Context ctx) {
+ super(rstc, "Kernel context default", ctx);
+ mRes = res;
+ }
+
+ private void initializeGlobals(RenderScript RS, ScriptC_ctxt_default s) {
+ Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
+ int X = 2;
+ s.set_gDimX(X);
+ typeBuilder.setX(X);
+
+ A = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_A(A);
+ B = Allocation.createTyped(RS, typeBuilder.create());
+ s.set_B(B);
+ return;
+ }
+
+ public void run() {
+ RenderScript pRS = RenderScript.create(mCtx);
+ ScriptC_ctxt_default s = new ScriptC_ctxt_default(pRS);
+ pRS.setMessageHandler(mRsMessage);
+ initializeGlobals(pRS, s);
+ s.forEach_init_vars(A);
+ s.forEach_root(A, B);
+ s.invoke_verify_root();
+ s.invoke_kernel_test();
+ pRS.finish();
+ waitForMessage();
+ pRS.destroy();
+ }
+}
diff --git a/java/tests/RsTest/src/com/android/rs/test/ctxt_default.rs b/java/tests/RsTest/src/com/android/rs/test/ctxt_default.rs
new file mode 100644
index 00000000..ba86ada8
--- /dev/null
+++ b/java/tests/RsTest/src/com/android/rs/test/ctxt_default.rs
@@ -0,0 +1,68 @@
+#include "shared.rsh"
+
+rs_allocation A;
+rs_allocation B;
+uint32_t gDimX;
+static bool failed = false;
+
+void init_vars(int *out) {
+ *out = 7;
+}
+
+int RS_KERNEL root(int ain, rs_kernel_context ctxt, uint32_t x) {
+ _RS_ASSERT_EQU(rsGetArray0(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetArray1(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetArray2(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetArray3(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetFace(ctxt), RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
+ _RS_ASSERT_EQU(rsGetLod(ctxt), 0);
+
+ _RS_ASSERT_EQU(rsGetDimY(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetDimZ(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetDimArray0(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetDimArray1(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetDimArray2(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetDimArray3(ctxt), 0);
+ _RS_ASSERT_EQU(rsGetDimHasFaces(ctxt), false);
+ _RS_ASSERT_EQU(rsGetDimLod(ctxt), 0);
+
+ if (!_RS_ASSERT_EQU(ain, 7))
+ rsDebug("root at x", x);
+ uint32_t dimX = rsGetDimX(ctxt);
+ _RS_ASSERT_EQU(dimX, gDimX);
+ return ain + x;
+}
+
+static bool test_root_output() {
+ bool failed = false;
+ int i;
+
+ for (i = 0; i < gDimX; i++) {
+ int bElt = rsGetElementAt_int(B, i);
+ int aElt = rsGetElementAt_int(A, i);
+ if (!_RS_ASSERT_EQU(bElt, (aElt + i)))
+ rsDebug("test_root_output at i", i);
+ }
+
+ if (failed) {
+ rsDebug("ctxt_default test_root_output FAILED", 0);
+ }
+ else {
+ rsDebug("ctxt_default test_root_output PASSED", 0);
+ }
+
+ return failed;
+}
+
+void verify_root() {
+ failed |= test_root_output();
+}
+
+void kernel_test() {
+ if (failed) {
+ rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+ }
+ else {
+ rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+ }
+}
diff --git a/scriptc/rs_core.rsh b/scriptc/rs_core.rsh
index b67db6ac..0aed990d 100644
--- a/scriptc/rs_core.rsh
+++ b/scriptc/rs_core.rsh
@@ -200,6 +200,48 @@ extern void __attribute__((overloadable))
#if (defined(RS_VERSION) && (RS_VERSION >= 23))
/**
+ * Return Array0 coordinate of kernel launch described by the specified launch context.
+ * Returns 0 if Array0 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetArray0(rs_kernel_context ctxt);
+
+/**
+ * Return Array1 coordinate of kernel launch described by the specified launch context.
+ * Returns 0 if Array1 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetArray1(rs_kernel_context ctxt);
+
+/**
+ * Return Array2 coordinate of kernel launch described by the specified launch context.
+ * Returns 0 if Array2 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetArray2(rs_kernel_context ctxt);
+
+/**
+ * Return Array3 coordinate of kernel launch described by the specified launch context.
+ * Returns 0 if Array3 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetArray3(rs_kernel_context ctxt);
+
+/**
+ * Return Face coordinate of kernel launch described by the specified launch context.
+ * Returns RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X if Face dimension is not present.
+ */
+extern rs_allocation_cubemap_face __attribute__((overloadable))
+ rsGetFace(rs_kernel_context ctxt);
+
+/**
+ * Return Lod coordinate of kernel launch described by the specificed launch context.
+ * Returns 0 if Lod dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetLod(rs_kernel_context ctxt);
+
+/**
* Return X dimension of kernel launch described by the specified launch context.
*/
extern uint32_t __attribute__((overloadable))
@@ -219,6 +261,47 @@ extern uint32_t __attribute__((overloadable))
extern uint32_t __attribute__((overloadable))
rsGetDimZ(rs_kernel_context ctxt);
+/**
+ * Return Array0 dimension of kernel launch described by the specificed launch context.
+ * Returns 0 if Array0 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetDimArray0(rs_kernel_context ctxt);
+
+/**
+ * Return Array1 dimension of kernel launch described by the specificed launch context.
+ * Returns 0 if Array1 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetDimArray1(rs_kernel_context ctxt);
+
+/**
+ * Return Array2 dimension of kernel launch described by the specificed launch context.
+ * Returns 0 if Array2 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetDimArray2(rs_kernel_context ctxt);
+
+/**
+ * Return Array3 dimension of kernel launch described by the specificed launch context.
+ * Returns 0 if Array3 dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetDimArray3(rs_kernel_context ctxt);
+
+/**
+ * Is the Faces dimension present in the kernel launch described by the specified launch context?
+ */
+extern bool __attribute__((overloadable))
+ rsGetDimHasFaces(rs_kernel_context ctxt);
+
+/**
+ * Return Lod dimension of kernel launch described by the specificed launch context.
+ * Returns 0 if Lod dimension is not present.
+ */
+extern uint32_t __attribute__((overloadable))
+ rsGetDimLod(rs_kernel_context ctxt);
+
#endif // (defined(RS_VERSION) && (RS_VERSION >= 23))
#endif