Skip to content

Commit a16c98c

Browse files
stephenhinesAndroid (Google) Code Review
authored andcommitted
Merge "Support running ForEach on non-root functions."
2 parents a172b6e + 473a204 commit a16c98c

File tree

12 files changed

+182
-27
lines changed

12 files changed

+182
-27
lines changed

libs/rs/driver/rsdBcc.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
1817
#include "rsdCore.h"
1918
#include "rsdBcc.h"
2019
#include "rsdRuntime.h"
@@ -30,7 +29,6 @@ extern "C" {
3029
#include "libdex/ZipArchive.h"
3130
}
3231

33-
3432
using namespace android;
3533
using namespace android::renderscript;
3634

@@ -45,6 +43,7 @@ struct DrvScript {
4543
bcinfo::MetadataExtractor *ME;
4644

4745
InvokeFunc_t *mInvokeFunctions;
46+
ForEachFunc_t *mForEachFunctions;
4847
void ** mFieldAddress;
4948
bool * mFieldIsObject;
5049
const uint32_t *mExportForEachSignatureList;
@@ -162,8 +161,16 @@ bool rsdScriptInit(const Context *rsc,
162161
}
163162

164163
exportForEachSignatureCount = drv->ME->getExportForEachSignatureCount();
165-
rsAssert(exportForEachSignatureCount <= 1);
166164
drv->mExportForEachSignatureList = drv->ME->getExportForEachSignatureList();
165+
if (exportForEachSignatureCount > 0) {
166+
drv->mForEachFunctions =
167+
(ForEachFunc_t*) calloc(exportForEachSignatureCount,
168+
sizeof(ForEachFunc_t));
169+
bccGetExportForEachList(drv->mBccScript, exportForEachSignatureCount,
170+
(void **) drv->mForEachFunctions);
171+
} else {
172+
drv->mForEachFunctions = NULL;
173+
}
167174

168175
// Copy info over to runtime
169176
script->mHal.info.exportedFunctionCount = drv->ME->getExportFuncCount();
@@ -196,6 +203,7 @@ bool rsdScriptInit(const Context *rsc,
196203
typedef struct {
197204
Context *rsc;
198205
Script *script;
206+
ForEachFunc_t kernel;
199207
uint32_t sig;
200208
const Allocation * ain;
201209
Allocation * aout;
@@ -235,7 +243,7 @@ static void wc_xy(void *usr, uint32_t idx) {
235243
RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv;
236244
uint32_t sig = mtls->sig;
237245

238-
outer_foreach_t fn = (outer_foreach_t) mtls->script->mHal.info.root;
246+
outer_foreach_t fn = (outer_foreach_t) mtls->kernel;
239247
while (1) {
240248
uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
241249
uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize;
@@ -265,7 +273,7 @@ static void wc_x(void *usr, uint32_t idx) {
265273
RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv;
266274
uint32_t sig = mtls->sig;
267275

268-
outer_foreach_t fn = (outer_foreach_t) mtls->script->mHal.info.root;
276+
outer_foreach_t fn = (outer_foreach_t) mtls->kernel;
269277
while (1) {
270278
uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
271279
uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize;
@@ -299,8 +307,8 @@ void rsdScriptInvokeForEach(const Context *rsc,
299307
memset(&mtls, 0, sizeof(mtls));
300308

301309
DrvScript *drv = (DrvScript *)s->mHal.drv;
302-
// We only support slot 0 (root) at this point in time.
303-
rsAssert(slot == 0);
310+
mtls.kernel = drv->mForEachFunctions[slot];
311+
rsAssert(mtls.kernel != NULL);
304312
mtls.sig = 0x1f; // temp fix for old apps, full table in slang_rs_export_foreach.cpp
305313
if (drv->mExportForEachSignatureList) {
306314
mtls.sig = drv->mExportForEachSignatureList[slot];
@@ -391,7 +399,7 @@ void rsdScriptInvokeForEach(const Context *rsc,
391399
uint32_t sig = mtls.sig;
392400

393401
//ALOGE("launch 3");
394-
outer_foreach_t fn = (outer_foreach_t) mtls.script->mHal.info.root;
402+
outer_foreach_t fn = (outer_foreach_t) mtls.kernel;
395403
for (p.ar[0] = mtls.arrayStart; p.ar[0] < mtls.arrayEnd; p.ar[0]++) {
396404
for (p.z = mtls.zStart; p.z < mtls.zEnd; p.z++) {
397405
for (p.y = mtls.yStart; p.y < mtls.yEnd; p.y++) {
@@ -517,6 +525,11 @@ void rsdScriptDestroy(const Context *dc, Script *script) {
517525
drv->mInvokeFunctions = NULL;
518526
}
519527

528+
if (drv->mForEachFunctions) {
529+
free(drv->mForEachFunctions);
530+
drv->mForEachFunctions = NULL;
531+
}
532+
520533
delete drv->ME;
521534
drv->ME = NULL;
522535

libs/rs/driver/rsdCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "rsdGL.h"
2626

2727
typedef void (* InvokeFunc_t)(void);
28+
typedef void (* ForEachFunc_t)(void);
2829
typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
2930

3031
typedef struct RsdSymbolTableRec {

libs/rs/rsScript.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -113,7 +113,7 @@ void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
113113
RsAllocation vain, RsAllocation vaout,
114114
const void *params, size_t paramLen) {
115115
Script *s = static_cast<Script *>(vs);
116-
s->runForEach(rsc,
116+
s->runForEach(rsc, slot,
117117
static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout),
118118
params, paramLen);
119119

libs/rs/rsScript.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,6 +74,7 @@ class Script : public ObjectBase {
7474
virtual bool freeChildren();
7575

7676
virtual void runForEach(Context *rsc,
77+
uint32_t slot,
7778
const Allocation * ain,
7879
Allocation * aout,
7980
const void * usr,

libs/rs/rsScriptC.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,6 +128,7 @@ uint32_t ScriptC::run(Context *rsc) {
128128

129129

130130
void ScriptC::runForEach(Context *rsc,
131+
uint32_t slot,
131132
const Allocation * ain,
132133
Allocation * aout,
133134
const void * usr,
@@ -138,7 +139,7 @@ void ScriptC::runForEach(Context *rsc,
138139

139140
setupGLState(rsc);
140141
setupScript(rsc);
141-
rsc->mHal.funcs.script.invokeForEach(rsc, this, 0, ain, aout, usr, usrBytes, sc);
142+
rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ain, aout, usr, usrBytes, sc);
142143
}
143144

144145
void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {

libs/rs/rsScriptC.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,6 +47,7 @@ class ScriptC : public Script {
4747
virtual uint32_t run(Context *);
4848

4949
virtual void runForEach(Context *rsc,
50+
uint32_t slot,
5051
const Allocation * ain,
5152
Allocation * aout,
5253
const void * usr,

libs/rs/rsScriptC_Lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2009 The Android Open Source Project
2+
* Copyright (C) 2009-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -157,7 +157,7 @@ void rsrForEach(Context *rsc, Script *sc,
157157
Allocation *in, Allocation *out,
158158
const void *usr, uint32_t usrBytes,
159159
const RsScriptCall *call) {
160-
target->runForEach(rsc, in, out, usr, usrBytes, call);
160+
target->runForEach(rsc, /* root slot */ 0, in, out, usr, usrBytes, call);
161161
}
162162

163163
void rsrAllocationSyncAll(Context *rsc, Script *sc, Allocation *a, RsAllocationUsageType usage) {

tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
6464

6565
unitTests = new ArrayList<UnitTest>();
6666

67-
unitTests.add(new UT_mesh(this, mRes, mCtx));
68-
unitTests.add(new UT_element(this, mRes, mCtx));
69-
unitTests.add(new UT_sampler(this, mRes, mCtx));
70-
unitTests.add(new UT_program_store(this, mRes, mCtx));
71-
unitTests.add(new UT_program_raster(this, mRes, mCtx));
7267
unitTests.add(new UT_primitives(this, mRes, mCtx));
7368
unitTests.add(new UT_constant(this, mRes, mCtx));
7469
unitTests.add(new UT_vector(this, mRes, mCtx));
@@ -79,10 +74,17 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
7974
unitTests.add(new UT_alloc(this, mRes, mCtx));
8075
unitTests.add(new UT_refcount(this, mRes, mCtx));
8176
unitTests.add(new UT_foreach(this, mRes, mCtx));
77+
unitTests.add(new UT_noroot(this, mRes, mCtx));
8278
unitTests.add(new UT_atomic(this, mRes, mCtx));
8379
unitTests.add(new UT_struct(this, mRes, mCtx));
8480
unitTests.add(new UT_math(this, mRes, mCtx));
81+
unitTests.add(new UT_mesh(this, mRes, mCtx));
82+
unitTests.add(new UT_element(this, mRes, mCtx));
83+
unitTests.add(new UT_sampler(this, mRes, mCtx));
84+
unitTests.add(new UT_program_store(this, mRes, mCtx));
85+
unitTests.add(new UT_program_raster(this, mRes, mCtx));
8586
unitTests.add(new UT_fp_mad(this, mRes, mCtx));
87+
8688
/*
8789
unitTests.add(new UnitTest(null, "<Pass>", 1));
8890
unitTests.add(new UnitTest());

tests/RenderScriptTests/tests/src/com/android/rs/test/UT_foreach.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011 The Android Open Source Project
2+
* Copyright (C) 2011-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,9 @@ public void run() {
4848
pRS.setMessageHandler(mRsMessage);
4949
initializeGlobals(pRS, s);
5050
s.forEach_root(A);
51+
s.invoke_verify_root();
52+
s.forEach_foo(A, A);
53+
s.invoke_verify_foo();
5154
s.invoke_foreach_test();
5255
pRS.finish();
5356
waitForMessage();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2011-2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.rs.test;
18+
19+
import android.content.Context;
20+
import android.content.res.Resources;
21+
import android.renderscript.*;
22+
23+
public class UT_noroot extends UnitTest {
24+
private Resources mRes;
25+
private Allocation A;
26+
27+
protected UT_noroot(RSTestCore rstc, Resources res, Context ctx) {
28+
super(rstc, "ForEach (no root)", ctx);
29+
mRes = res;
30+
}
31+
32+
private void initializeGlobals(RenderScript RS, ScriptC_noroot s) {
33+
Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
34+
int X = 5;
35+
int Y = 7;
36+
s.set_dimX(X);
37+
s.set_dimY(Y);
38+
typeBuilder.setX(X).setY(Y);
39+
A = Allocation.createTyped(RS, typeBuilder.create());
40+
s.bind_a(A);
41+
42+
return;
43+
}
44+
45+
public void run() {
46+
RenderScript pRS = RenderScript.create(mCtx);
47+
ScriptC_noroot s = new ScriptC_noroot(pRS, mRes, R.raw.noroot);
48+
pRS.setMessageHandler(mRsMessage);
49+
initializeGlobals(pRS, s);
50+
s.forEach_foo(A, A);
51+
s.invoke_verify_foo();
52+
s.invoke_noroot_test();
53+
pRS.finish();
54+
waitForMessage();
55+
pRS.destroy();
56+
}
57+
}

0 commit comments

Comments
 (0)