diff options
5 files changed, 171 insertions, 54 deletions
diff --git a/libs/rs/driver/rsdRuntimeStubs.cpp b/libs/rs/driver/rsdRuntimeStubs.cpp index d8050ac..90c8928 100644 --- a/libs/rs/driver/rsdRuntimeStubs.cpp +++ b/libs/rs/driver/rsdRuntimeStubs.cpp @@ -42,41 +42,6 @@ using namespace android::renderscript; // Allocation ////////////////////////////////////////////////////////////////////////////// -static uint32_t SC_allocGetDimX(Allocation *a) { - return a->mHal.state.dimensionX; -} - -static uint32_t SC_allocGetDimY(Allocation *a) { - return a->mHal.state.dimensionY; -} - -static uint32_t SC_allocGetDimZ(Allocation *a) { - return a->mHal.state.dimensionZ; -} - -static uint32_t SC_allocGetDimLOD(Allocation *a) { - return a->mHal.state.hasMipmaps; -} - -static uint32_t SC_allocGetDimFaces(Allocation *a) { - return a->mHal.state.hasFaces; -} - -static const void * SC_getElementAtX(Allocation *a, uint32_t x) { - const uint8_t *p = (const uint8_t *)a->getPtr(); - return &p[a->mHal.state.elementSizeBytes * x]; -} - -static const void * SC_getElementAtXY(Allocation *a, uint32_t x, uint32_t y) { - const uint8_t *p = (const uint8_t *)a->getPtr(); - return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX)]; -} - -static const void * SC_getElementAtXYZ(Allocation *a, uint32_t x, uint32_t y, uint32_t z) { - const uint8_t *p = (const uint8_t *)a->getPtr(); - return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX + - z * a->mHal.state.dimensionX * a->mHal.state.dimensionY)]; -} static void SC_AllocationSyncAll2(Allocation *a, RsAllocationUsageType source) { GET_TLS(); @@ -115,12 +80,6 @@ static void SC_AllocationCopy2DRange(Allocation *dstAlloc, } -const Allocation * SC_getAllocation(const void *ptr) { - GET_TLS(); - return rsrGetAllocation(rsc, sc, ptr); -} - - ////////////////////////////////////////////////////////////////////////////// // Context ////////////////////////////////////////////////////////////////////////////// @@ -599,18 +558,6 @@ static RsdSymbolTable gSyms[] = { { "_Z10rsIsObject7rs_font", (void *)&SC_IsObject, true }, // Allocation ops - { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true }, - { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true }, - { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true }, - { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true }, - { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true }, - - { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true }, - { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true }, - { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true }, - - { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true }, - { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true }, { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false }, { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false }, diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index f538dd1..f2589c0 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -25,8 +25,16 @@ namespace renderscript { class Program; +/***************************************************************************** + * 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 Allocation : public ObjectBase { - // The graphics equilivent of malloc. The allocation contains a structure of elements. + // The graphics equivalent of malloc. The allocation contains a structure of elements. public: struct Hal { diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java index e77998e..be012ee 100644 --- a/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java @@ -69,6 +69,7 @@ public class RSTestCore { unitTests.add(new UT_rsdebug(this, mRes, mCtx)); unitTests.add(new UT_rstime(this, mRes, mCtx)); unitTests.add(new UT_rstypes(this, mRes, mCtx)); + unitTests.add(new UT_alloc(this, mRes, mCtx)); unitTests.add(new UT_math(this, mRes, mCtx)); unitTests.add(new UT_fp_mad(this, mRes, mCtx)); /* diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_alloc.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_alloc.java new file mode 100644 index 0000000..b583b1c --- /dev/null +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_alloc.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011 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.*; + +public class UT_alloc extends UnitTest { + private Resources mRes; + + protected UT_alloc(RSTestCore rstc, Resources res, Context ctx) { + super(rstc, "Alloc", ctx); + mRes = res; + } + + private void initializeGlobals(RenderScript RS, ScriptC_alloc s) { + Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS)); + int X = 5; + int Y = 7; + int Z = 0; + s.set_dimX(X); + s.set_dimY(Y); + s.set_dimZ(Z); + typeBuilder.setX(X).setY(Y); + Allocation A = Allocation.createTyped(RS, typeBuilder.create()); + s.bind_a(A); + + typeBuilder = new Type.Builder(RS, Element.I32(RS)); + typeBuilder.setX(X).setY(Y).setFaces(true); + Allocation AFaces = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aFaces(AFaces); + typeBuilder.setFaces(false).setMipmaps(true); + Allocation ALOD = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aLOD(ALOD); + typeBuilder.setFaces(true).setMipmaps(true); + Allocation AFacesLOD = Allocation.createTyped(RS, typeBuilder.create()); + s.set_aFacesLOD(AFacesLOD); + + return; + } + + public void run() { + RenderScript pRS = RenderScript.create(mCtx); + ScriptC_alloc s = new ScriptC_alloc(pRS, mRes, R.raw.alloc); + pRS.setMessageHandler(mRsMessage); + initializeGlobals(pRS, s); + s.invoke_alloc_test(); + pRS.finish(); + waitForMessage(); + pRS.destroy(); + } +} diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/alloc.rs b/tests/RenderScriptTests/tests/src/com/android/rs/test/alloc.rs new file mode 100644 index 0000000..3116e5a --- /dev/null +++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/alloc.rs @@ -0,0 +1,94 @@ +#include "shared.rsh" + +int *a; +int dimX; +int dimY; +int dimZ; + +rs_allocation aFaces; +rs_allocation aLOD; +rs_allocation aFacesLOD; + +static bool test_alloc_dims() { + bool failed = false; + int i, j; + + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + a[i + j * dimX] = i + j * dimX; + } + } + + rs_allocation alloc = rsGetAllocation(a); + _RS_ASSERT(rsAllocationGetDimX(alloc) == dimX); + _RS_ASSERT(rsAllocationGetDimY(alloc) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(alloc) == dimZ); + + // Test 2D addressing + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + rsDebug("Verifying ", i + j * dimX); + const void *p = rsGetElementAt(alloc, i, j); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + // Test 1D addressing + for (i = 0; i < dimX * dimY; i++) { + rsDebug("Verifying ", i); + const void *p = rsGetElementAt(alloc, i); + int val = *(const int *)p; + _RS_ASSERT(val == i); + } + + // Test 3D addressing + for (j = 0; j < dimY; j++) { + for (i = 0; i < dimX; i++) { + rsDebug("Verifying ", i + j * dimX); + const void *p = rsGetElementAt(alloc, i, j, 0); + int val = *(const int *)p; + _RS_ASSERT(val == (i + j * dimX)); + } + } + + _RS_ASSERT(rsAllocationGetDimX(aFaces) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aFaces) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aFaces) == dimZ); + _RS_ASSERT(rsAllocationGetDimFaces(aFaces) != 0); + _RS_ASSERT(rsAllocationGetDimLOD(aFaces) == 0); + + _RS_ASSERT(rsAllocationGetDimX(aLOD) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aLOD) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aLOD) == dimZ); + _RS_ASSERT(rsAllocationGetDimFaces(aLOD) == 0); + _RS_ASSERT(rsAllocationGetDimLOD(aLOD) != 0); + + _RS_ASSERT(rsAllocationGetDimX(aFacesLOD) == dimX); + _RS_ASSERT(rsAllocationGetDimY(aFacesLOD) == dimY); + _RS_ASSERT(rsAllocationGetDimZ(aFacesLOD) == dimZ); + _RS_ASSERT(rsAllocationGetDimFaces(aFacesLOD) != 0); + _RS_ASSERT(rsAllocationGetDimLOD(aFacesLOD) != 0); + + if (failed) { + rsDebug("test_alloc_dims FAILED", 0); + } + else { + rsDebug("test_alloc_dims PASSED", 0); + } + + return failed; +} + +void alloc_test() { + bool failed = false; + failed |= test_alloc_dims(); + + if (failed) { + rsSendToClientBlocking(RS_MSG_TEST_FAILED); + } + else { + rsSendToClientBlocking(RS_MSG_TEST_PASSED); + } +} + |