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-
3432using namespace android ;
3533using 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,
196203typedef 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
0 commit comments