diff options
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/driver/rsdBcc.cpp | 34 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 175 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.h | 9 | ||||
-rw-r--r-- | libs/rs/driver/rsdGL.cpp | 4 | ||||
-rw-r--r-- | libs/rs/driver/rsdGL.h | 4 | ||||
-rw-r--r-- | libs/rs/driver/rsdRuntimeMath.cpp | 34 | ||||
-rw-r--r-- | libs/rs/driver/rsdShader.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rs.spec | 4 | ||||
-rw-r--r-- | libs/rs/rsAllocation.cpp | 151 | ||||
-rw-r--r-- | libs/rs/rsAllocation.h | 17 | ||||
-rw-r--r-- | libs/rs/rsComponent.cpp | 3 | ||||
-rw-r--r-- | libs/rs/rsComponent.h | 2 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 24 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 3 | ||||
-rw-r--r-- | libs/rs/rsElement.cpp | 17 | ||||
-rw-r--r-- | libs/rs/rsElement.h | 12 | ||||
-rw-r--r-- | libs/rs/rsFont.cpp | 16 | ||||
-rw-r--r-- | libs/rs/rsFont.h | 3 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 5 | ||||
-rw-r--r-- | libs/rs/rsScript.cpp | 20 | ||||
-rw-r--r-- | libs/rs/rsScript.h | 3 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 14 | ||||
-rw-r--r-- | libs/rs/rsScriptC_LibGL.cpp | 5 | ||||
-rw-r--r-- | libs/rs/rsThreadIO.cpp | 9 | ||||
-rw-r--r-- | libs/rs/scriptc/rs_atomic.rsh | 2 | ||||
-rw-r--r-- | libs/rs/scriptc/rs_types.rsh | 2 |
26 files changed, 310 insertions, 266 deletions
diff --git a/libs/rs/driver/rsdBcc.cpp b/libs/rs/driver/rsdBcc.cpp index a36bae9..bec6fff 100644 --- a/libs/rs/driver/rsdBcc.cpp +++ b/libs/rs/driver/rsdBcc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 The Android Open Source Project + * Copyright (C) 2011-2012 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. @@ -36,6 +36,7 @@ using namespace android::renderscript; struct DrvScript { int (*mRoot)(); + int (*mRootExpand)(); void (*mInit)(); void (*mFreeChildren)(); @@ -52,6 +53,10 @@ struct DrvScript { uint32_t mScriptTextLength; }; +typedef void (*outer_foreach_t)( + const android::renderscript::RsForEachStubParamStruct *, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep); static Script * setTLS(Script *sc) { ScriptTLSStruct * tls = (ScriptTLSStruct *)pthread_getspecific(rsdgThreadTLSKey); @@ -72,7 +77,7 @@ bool rsdScriptInit(const Context *rsc, //ALOGE("rsdScriptCreate %p %p %p %p %i %i %p", rsc, resName, cacheDir, bitcode, bitcodeSize, flags, lookupFunc); pthread_mutex_lock(&rsdgInitMutex); - char *cachePath = NULL; + size_t exportFuncCount = 0; size_t exportVarCount = 0; size_t objectSlotCount = 0; @@ -122,9 +127,8 @@ bool rsdScriptInit(const Context *rsc, goto error; } - free(cachePath); - drv->mRoot = reinterpret_cast<int (*)()>(bccGetFuncAddr(drv->mBccScript, "root")); + drv->mRootExpand = reinterpret_cast<int (*)()>(bccGetFuncAddr(drv->mBccScript, "root.expand")); drv->mInit = reinterpret_cast<void (*)()>(bccGetFuncAddr(drv->mBccScript, "init")); drv->mFreeChildren = reinterpret_cast<void (*)()>(bccGetFuncAddr(drv->mBccScript, ".rs.dtor")); @@ -167,7 +171,12 @@ bool rsdScriptInit(const Context *rsc, script->mHal.info.exportedPragmaCount = drv->ME->getPragmaCount(); script->mHal.info.exportedPragmaKeyList = drv->ME->getPragmaKeyList(); script->mHal.info.exportedPragmaValueList = drv->ME->getPragmaValueList(); - script->mHal.info.root = drv->mRoot; + + if (drv->mRootExpand) { + script->mHal.info.root = drv->mRootExpand; + } else { + script->mHal.info.root = drv->mRoot; + } pthread_mutex_unlock(&rsdgInitMutex); return true; @@ -226,7 +235,7 @@ static void wc_xy(void *usr, uint32_t idx) { RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv; uint32_t sig = mtls->sig; - outer_foreach_t fn = dc->mForEachLaunch[sig]; + outer_foreach_t fn = (outer_foreach_t) mtls->script->mHal.info.root; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize; @@ -242,8 +251,7 @@ static void wc_xy(void *usr, uint32_t idx) { uint32_t offset = mtls->dimX * p.y; p.out = mtls->ptrOut + (mtls->eStrideOut * offset); p.in = mtls->ptrIn + (mtls->eStrideIn * offset); - fn(&mtls->script->mHal.info.root, &p, mtls->xStart, mtls->xEnd, - mtls->eStrideIn, mtls->eStrideOut); + fn(&p, mtls->xStart, mtls->xEnd, mtls->eStrideIn, mtls->eStrideOut); } } } @@ -257,7 +265,7 @@ static void wc_x(void *usr, uint32_t idx) { RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv; uint32_t sig = mtls->sig; - outer_foreach_t fn = dc->mForEachLaunch[sig]; + outer_foreach_t fn = (outer_foreach_t) mtls->script->mHal.info.root; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize; @@ -272,7 +280,7 @@ static void wc_x(void *usr, uint32_t idx) { p.out = mtls->ptrOut + (mtls->eStrideOut * xStart); p.in = mtls->ptrIn + (mtls->eStrideIn * xStart); - fn(&mtls->script->mHal.info.root, &p, xStart, xEnd, mtls->eStrideIn, mtls->eStrideOut); + fn(&p, xStart, xEnd, mtls->eStrideIn, mtls->eStrideOut); } } @@ -383,7 +391,7 @@ void rsdScriptInvokeForEach(const Context *rsc, uint32_t sig = mtls.sig; //ALOGE("launch 3"); - outer_foreach_t fn = dc->mForEachLaunch[sig]; + outer_foreach_t fn = (outer_foreach_t) mtls.script->mHal.info.root; for (p.ar[0] = mtls.arrayStart; p.ar[0] < mtls.arrayEnd; p.ar[0]++) { for (p.z = mtls.zStart; p.z < mtls.zEnd; p.z++) { for (p.y = mtls.yStart; p.y < mtls.yEnd; p.y++) { @@ -392,8 +400,8 @@ void rsdScriptInvokeForEach(const Context *rsc, mtls.dimX * p.y; p.out = mtls.ptrOut + (mtls.eStrideOut * offset); p.in = mtls.ptrIn + (mtls.eStrideIn * offset); - fn(&mtls.script->mHal.info.root, &p, mtls.xStart, mtls.xEnd, - mtls.eStrideIn, mtls.eStrideOut); + fn(&p, mtls.xStart, mtls.xEnd, mtls.eStrideIn, + mtls.eStrideOut); } } } diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index b514e21..1a535d0 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 The Android Open Source Project + * Copyright (C) 2011-2012 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. @@ -43,7 +43,6 @@ using namespace android::renderscript; static void Shutdown(Context *rsc); static void SetPriority(const Context *rsc, int32_t priority); -static void initForEach(outer_foreach_t* forEachLaunch); static RsdHalFunctions FunctionTable = { rsdGLInit, @@ -208,8 +207,6 @@ bool rsdHalInit(Context *rsc, uint32_t version_major, uint32_t version_minor) { rsdgThreadTLSKeyCount++; pthread_mutex_unlock(&rsdgInitMutex); - initForEach(dc->mForEachLaunch); - dc->mTlsStruct.mContext = rsc; dc->mTlsStruct.mScript = NULL; int status = pthread_setspecific(rsdgThreadTLSKey, &dc->mTlsStruct); @@ -291,173 +288,3 @@ void Shutdown(Context *rsc) { } -static void rsdForEach17(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, uint32_t); - (*(fe*)vRoot)(p->in, p->y); -} - -static void rsdForEach18(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(void *, uint32_t); - (*(fe*)vRoot)(p->out, p->y); -} - -static void rsdForEach19(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, void *, uint32_t); - (*(fe*)vRoot)(p->in, p->out, p->y); -} - -static void rsdForEach21(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, const void *, uint32_t); - (*(fe*)vRoot)(p->in, p->usr, p->y); -} - -static void rsdForEach22(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(void *, const void *, uint32_t); - (*(fe*)vRoot)(p->out, p->usr, p->y); -} - -static void rsdForEach23(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, void *, const void *, uint32_t); - (*(fe*)vRoot)(p->in, p->out, p->usr, p->y); -} - -static void rsdForEach25(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, uint32_t, uint32_t); - const uint8_t *pin = (const uint8_t *)p->in; - uint32_t y = p->y; - for (uint32_t x = x1; x < x2; x++) { - (*(fe*)vRoot)(pin, x, y); - pin += instep; - } -} - -static void rsdForEach26(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(void *, uint32_t, uint32_t); - uint8_t *pout = (uint8_t *)p->out; - uint32_t y = p->y; - for (uint32_t x = x1; x < x2; x++) { - (*(fe*)vRoot)(pout, x, y); - pout += outstep; - } -} - -static void rsdForEach27(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, void *, uint32_t, uint32_t); - uint8_t *pout = (uint8_t *)p->out; - const uint8_t *pin = (const uint8_t *)p->in; - uint32_t y = p->y; - for (uint32_t x = x1; x < x2; x++) { - (*(fe*)vRoot)(pin, pout, x, y); - pin += instep; - pout += outstep; - } -} - -static void rsdForEach29(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, const void *, uint32_t, uint32_t); - const uint8_t *pin = (const uint8_t *)p->in; - const void *usr = p->usr; - const uint32_t y = p->y; - for (uint32_t x = x1; x < x2; x++) { - (*(fe*)vRoot)(pin, usr, x, y); - pin += instep; - } -} - -static void rsdForEach30(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(void *, const void *, uint32_t, uint32_t); - uint8_t *pout = (uint8_t *)p->out; - const void *usr = p->usr; - const uint32_t y = p->y; - for (uint32_t x = x1; x < x2; x++) { - (*(fe*)vRoot)(pout, usr, x, y); - pout += outstep; - } -} - -static void rsdForEach31(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep) { - typedef void (*fe)(const void *, void *, const void *, uint32_t, uint32_t); - uint8_t *pout = (uint8_t *)p->out; - const uint8_t *pin = (const uint8_t *)p->in; - const void *usr = p->usr; - const uint32_t y = p->y; - for (uint32_t x = x1; x < x2; x++) { - (*(fe*)vRoot)(pin, pout, usr, x, y); - pin += instep; - pout += outstep; - } -} - - -static void initForEach(outer_foreach_t* forEachLaunch) { - rsAssert(forEachLaunch); - forEachLaunch[0x00] = NULL; - forEachLaunch[0x01] = rsdForEach31; // in - forEachLaunch[0x02] = rsdForEach30; // out - forEachLaunch[0x03] = rsdForEach31; // in, out - forEachLaunch[0x04] = NULL; - forEachLaunch[0x05] = rsdForEach29; // in, usr - forEachLaunch[0x06] = rsdForEach30; // out, usr - forEachLaunch[0x07] = rsdForEach31; // in, out, usr - forEachLaunch[0x08] = NULL; - forEachLaunch[0x09] = rsdForEach25; // in, x - forEachLaunch[0x0a] = rsdForEach26; // out, x - forEachLaunch[0x0b] = rsdForEach27; // in, out, x - forEachLaunch[0x0c] = NULL; - forEachLaunch[0x0d] = rsdForEach29; // in, usr, x - forEachLaunch[0x0e] = rsdForEach30; // out, usr, x - forEachLaunch[0x0f] = rsdForEach31; // in, out, usr, x - forEachLaunch[0x10] = NULL; - forEachLaunch[0x11] = rsdForEach17; // in y - forEachLaunch[0x12] = rsdForEach18; // out, y - forEachLaunch[0x13] = rsdForEach19; // in, out, y - forEachLaunch[0x14] = NULL; - forEachLaunch[0x15] = rsdForEach21; // in, usr, y - forEachLaunch[0x16] = rsdForEach22; // out, usr, y - forEachLaunch[0x17] = rsdForEach23; // in, out, usr, y - forEachLaunch[0x18] = NULL; - forEachLaunch[0x19] = rsdForEach25; // in, x, y - forEachLaunch[0x1a] = rsdForEach26; // out, x, y - forEachLaunch[0x1b] = rsdForEach27; // in, out, x, y - forEachLaunch[0x1c] = NULL; - forEachLaunch[0x1d] = rsdForEach29; // in, usr, x, y - forEachLaunch[0x1e] = rsdForEach30; // out, usr, x, y - forEachLaunch[0x1f] = rsdForEach31; // in, out, usr, x, y -} - diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h index ce86d11..126c87a 100644 --- a/libs/rs/driver/rsdCore.h +++ b/libs/rs/driver/rsdCore.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 The Android Open Source Project + * Copyright (C) 2011-2012 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. @@ -27,11 +27,6 @@ typedef void (* InvokeFunc_t)(void); typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); -typedef void (*outer_foreach_t)(const void *, - const android::renderscript::RsForEachStubParamStruct *, - uint32_t x1, uint32_t x2, - uint32_t instep, uint32_t outstep); - typedef struct RsdSymbolTableRec { const char * mName; void * mPtr; @@ -62,8 +57,6 @@ typedef struct RsdHalRec { Workers mWorkers; bool mExit; - outer_foreach_t mForEachLaunch[32]; - ScriptTLSStruct mTlsStruct; RsdGL gl; diff --git a/libs/rs/driver/rsdGL.cpp b/libs/rs/driver/rsdGL.cpp index b53a68c..7acc054 100644 --- a/libs/rs/driver/rsdGL.cpp +++ b/libs/rs/driver/rsdGL.cpp @@ -340,9 +340,9 @@ bool rsdGLInit(const Context *rsc) { dc->gl.gl.OES_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions, "GL_OES_texture_npot"); - dc->gl.gl.GL_IMG_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions, + dc->gl.gl.IMG_texture_npot = NULL != strstr((const char *)dc->gl.gl.extensions, "GL_IMG_texture_npot"); - dc->gl.gl.GL_NV_texture_npot_2D_mipmap = NULL != strstr((const char *)dc->gl.gl.extensions, + dc->gl.gl.NV_texture_npot_2D_mipmap = NULL != strstr((const char *)dc->gl.gl.extensions, "GL_NV_texture_npot_2D_mipmap"); dc->gl.gl.EXT_texture_max_aniso = 1.0f; bool hasAniso = NULL != strstr((const char *)dc->gl.gl.extensions, diff --git a/libs/rs/driver/rsdGL.h b/libs/rs/driver/rsdGL.h index fc33885..51893c3 100644 --- a/libs/rs/driver/rsdGL.h +++ b/libs/rs/driver/rsdGL.h @@ -61,8 +61,8 @@ typedef struct RsdGLRec { int32_t maxVertexTextureUnits; bool OES_texture_npot; - bool GL_IMG_texture_npot; - bool GL_NV_texture_npot_2D_mipmap; + bool IMG_texture_npot; + bool NV_texture_npot_2D_mipmap; float EXT_texture_max_aniso; } gl; diff --git a/libs/rs/driver/rsdRuntimeMath.cpp b/libs/rs/driver/rsdRuntimeMath.cpp index 4c300b7..753ef73 100644 --- a/libs/rs/driver/rsdRuntimeMath.cpp +++ b/libs/rs/driver/rsdRuntimeMath.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <cutils/compiler.h> + #include "rsContext.h" #include "rsScriptC.h" #include "rsMatrix4x4.h" @@ -306,7 +308,7 @@ static int32_t SC_AtomicSub(volatile int32_t *ptr, int32_t value) { do { prev = *ptr; status = android_atomic_release_cas(prev, prev - value, ptr); - } while (__builtin_expect(status != 0, 0)); + } while (CC_UNLIKELY(status != 0)); return prev; } @@ -323,7 +325,17 @@ static int32_t SC_AtomicXor(volatile int32_t *ptr, int32_t value) { do { prev = *ptr; status = android_atomic_release_cas(prev, prev ^ value, ptr); - } while (__builtin_expect(status != 0, 0)); + } while (CC_UNLIKELY(status != 0)); + return prev; +} + +static uint32_t SC_AtomicUMin(volatile uint32_t *ptr, uint32_t value) { + uint32_t prev, status; + do { + prev = *ptr; + uint32_t n = rsMin(value, prev); + status = android_atomic_release_cas((int32_t) prev, (int32_t)n, (volatile int32_t*) ptr); + } while (CC_UNLIKELY(status != 0)); return prev; } @@ -333,7 +345,17 @@ static int32_t SC_AtomicMin(volatile int32_t *ptr, int32_t value) { prev = *ptr; int32_t n = rsMin(value, prev); status = android_atomic_release_cas(prev, n, ptr); - } while (__builtin_expect(status != 0, 0)); + } while (CC_UNLIKELY(status != 0)); + return prev; +} + +static uint32_t SC_AtomicUMax(volatile uint32_t *ptr, uint32_t value) { + uint32_t prev, status; + do { + prev = *ptr; + uint32_t n = rsMax(value, prev); + status = android_atomic_release_cas((int32_t) prev, (int32_t) n, (volatile int32_t*) ptr); + } while (CC_UNLIKELY(status != 0)); return prev; } @@ -343,7 +365,7 @@ static int32_t SC_AtomicMax(volatile int32_t *ptr, int32_t value) { prev = *ptr; int32_t n = rsMax(value, prev); status = android_atomic_release_cas(prev, n, ptr); - } while (__builtin_expect(status != 0, 0)); + } while (CC_UNLIKELY(status != 0)); return prev; } @@ -522,9 +544,9 @@ static RsdSymbolTable gSyms[] = { { "_Z11rsAtomicXorPVii", (void *)&SC_AtomicXor, true }, { "_Z11rsAtomicXorPVjj", (void *)&SC_AtomicXor, true }, { "_Z11rsAtomicMinPVii", (void *)&SC_AtomicMin, true }, - { "_Z11rsAtomicMinPVjj", (void *)&SC_AtomicMin, true }, + { "_Z11rsAtomicMinPVjj", (void *)&SC_AtomicUMin, true }, { "_Z11rsAtomicMaxPVii", (void *)&SC_AtomicMax, true }, - { "_Z11rsAtomicMaxPVjj", (void *)&SC_AtomicMax, true }, + { "_Z11rsAtomicMaxPVjj", (void *)&SC_AtomicUMax, true }, { "_Z11rsAtomicCasPViii", (void *)&SC_AtomicCas, true }, { "_Z11rsAtomicCasPVjjj", (void *)&SC_AtomicCas, true }, diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp index a10deb4..c70193a 100644 --- a/libs/rs/driver/rsdShader.cpp +++ b/libs/rs/driver/rsdShader.cpp @@ -349,8 +349,8 @@ void RsdShader::setupSampler(const Context *rsc, const Sampler *s, const Allocat if (!dc->gl.gl.OES_texture_npot && tex->getType()->getIsNp2()) { if (tex->getHasGraphicsMipmaps() && - (dc->gl.gl.GL_NV_texture_npot_2D_mipmap || dc->gl.gl.GL_IMG_texture_npot)) { - if (dc->gl.gl.GL_NV_texture_npot_2D_mipmap) { + (dc->gl.gl.NV_texture_npot_2D_mipmap || dc->gl.gl.IMG_texture_npot)) { + if (dc->gl.gl.NV_texture_npot_2D_mipmap) { RSD_CALL_GL(glTexParameteri, target, GL_TEXTURE_MIN_FILTER, trans[s->mHal.state.minFilter]); } else { diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 20b1f52..6887b22 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -162,7 +162,7 @@ Allocation1DElementData { param uint32_t x param uint32_t lod param const void *data - param uint32_t comp_offset + param size_t comp_offset } Allocation2DData { @@ -183,7 +183,7 @@ Allocation2DElementData { param uint32_t lod param RsAllocationCubemapFace face param const void *data - param uint32_t element_offset + param size_t element_offset } AllocationGenerateMipmaps { diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 7b92b39..fd85b07 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2009-2012 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. @@ -71,11 +71,11 @@ void Allocation::read(void *data) { } void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, - uint32_t count, const void *data, uint32_t sizeBytes) { - const uint32_t eSize = mHal.state.type->getElementSizeBytes(); + uint32_t count, const void *data, size_t sizeBytes) { + const size_t eSize = mHal.state.type->getElementSizeBytes(); if ((count * eSize) != sizeBytes) { - ALOGE("Allocation::subData called with mismatched size expected %i, got %i", + ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu", (count * eSize), sizeBytes); mHal.state.type->dumpLOGV("type info"); return; @@ -86,14 +86,14 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, } void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, - uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes) { - const uint32_t eSize = mHal.state.elementSizeBytes; - const uint32_t lineSize = eSize * w; + uint32_t w, uint32_t h, const void *data, size_t sizeBytes) { + const size_t eSize = mHal.state.elementSizeBytes; + const size_t lineSize = eSize * w; //ALOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes); if ((lineSize * h) != sizeBytes) { - ALOGE("Allocation size mismatch, expected %i, got %i", (lineSize * h), sizeBytes); + ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes); rsAssert(!"Allocation::subData called with mismatched size"); return; } @@ -104,12 +104,12 @@ void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, RsAllocationCubemapFace face, - uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes) { + uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes) { } void Allocation::elementData(Context *rsc, uint32_t x, const void *data, - uint32_t cIdx, uint32_t sizeBytes) { - uint32_t eSize = mHal.state.elementSizeBytes; + uint32_t cIdx, size_t sizeBytes) { + size_t eSize = mHal.state.elementSizeBytes; if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { ALOGE("Error Allocation::subElementData component %i out of range.", cIdx); @@ -124,8 +124,9 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data, } const Element * e = mHal.state.type->getElement()->getField(cIdx); - if (sizeBytes != e->getSizeBytes()) { - ALOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes()); + uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); + if (sizeBytes != e->getSizeBytes() * elemArraySize) { + ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes()); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); return; } @@ -135,8 +136,8 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data, } void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, - const void *data, uint32_t cIdx, uint32_t sizeBytes) { - uint32_t eSize = mHal.state.elementSizeBytes; + const void *data, uint32_t cIdx, size_t sizeBytes) { + size_t eSize = mHal.state.elementSizeBytes; if (x >= mHal.state.dimensionX) { ALOGE("Error Allocation::subElementData X offset %i out of range.", x); @@ -157,9 +158,9 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, } const Element * e = mHal.state.type->getElement()->getField(cIdx); - - if (sizeBytes != e->getSizeBytes()) { - ALOGE("Error Allocation::subElementData data size %i does not match field size %zu.", sizeBytes, e->getSizeBytes()); + uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); + if (sizeBytes != e->getSizeBytes() * elemArraySize) { + ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes()); rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); return; } @@ -195,6 +196,81 @@ void Allocation::dumpLOGV(const char *prefix) const { prefix, getPtr(), mHal.state.usageFlags, mHal.state.mipmapControl); } +uint32_t Allocation::getPackedSize() const { + uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(); + return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded(); +} + +void Allocation::writePackedData(const Type *type, + uint8_t *dst, const uint8_t *src, bool dstPadded) { + const Element *elem = type->getElement(); + uint32_t unpaddedBytes = elem->getSizeBytesUnpadded(); + uint32_t paddedBytes = elem->getSizeBytes(); + uint32_t numItems = type->getSizeBytes() / paddedBytes; + + uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes; + uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes; + + // no sub-elements + uint32_t fieldCount = elem->getFieldCount(); + if (fieldCount == 0) { + for (uint32_t i = 0; i < numItems; i ++) { + memcpy(dst, src, unpaddedBytes); + src += srcInc; + dst += dstInc; + } + return; + } + + // Cache offsets + uint32_t *offsetsPadded = new uint32_t[fieldCount]; + uint32_t *offsetsUnpadded = new uint32_t[fieldCount]; + uint32_t *sizeUnpadded = new uint32_t[fieldCount]; + + for (uint32_t i = 0; i < fieldCount; i++) { + offsetsPadded[i] = elem->getFieldOffsetBytes(i); + offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i); + sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded(); + } + + uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded; + uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded; + + // complex elements, need to copy subelem after subelem + for (uint32_t i = 0; i < numItems; i ++) { + for (uint32_t fI = 0; fI < fieldCount; fI++) { + memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]); + } + src += srcInc; + dst += dstInc; + } + + delete[] offsetsPadded; + delete[] offsetsUnpadded; + delete[] sizeUnpadded; +} + +void Allocation::unpackVec3Allocation(const void *data, size_t dataSize) { + const uint8_t *src = (const uint8_t*)data; + uint8_t *dst = (uint8_t*)getPtr(); + + writePackedData(getType(), dst, src, true); +} + +void Allocation::packVec3Allocation(OStream *stream) const { + uint32_t paddedBytes = getType()->getElement()->getSizeBytes(); + uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded(); + uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes; + + const uint8_t *src = (const uint8_t*)getPtr(); + uint8_t *dst = new uint8_t[numItems * unpaddedBytes]; + + writePackedData(getType(), dst, src, false); + stream->addByteArray(dst, getPackedSize()); + + delete[] dst; +} + void Allocation::serialize(OStream *stream) const { // Need to identify ourselves stream->addU32((uint32_t)getClassId()); @@ -207,10 +283,17 @@ void Allocation::serialize(OStream *stream) const { mHal.state.type->serialize(stream); uint32_t dataSize = mHal.state.type->getSizeBytes(); + // 3 element vectors are padded to 4 in memory, but padding isn't serialized + uint32_t packedSize = getPackedSize(); // Write how much data we are storing - stream->addU32(dataSize); - // Now write the data - stream->addByteArray(getPtr(), dataSize); + stream->addU32(packedSize); + if (dataSize == packedSize) { + // Now write the data + stream->addByteArray(getPtr(), dataSize); + } else { + // Now write the data + packVec3Allocation(stream); + } } Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { @@ -230,22 +313,30 @@ Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { } type->compute(); + Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT); + type->decUserRef(); + // Number of bytes we wrote out for this allocation uint32_t dataSize = stream->loadU32(); - if (dataSize != type->getSizeBytes()) { + // 3 element vectors are padded to 4 in memory, but padding isn't serialized + uint32_t packedSize = alloc->getPackedSize(); + if (dataSize != type->getSizeBytes() && + dataSize != packedSize) { ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n"); + ObjectBase::checkDelete(alloc); ObjectBase::checkDelete(type); return NULL; } - Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT); alloc->setName(name.string(), name.size()); - type->decUserRef(); - uint32_t count = dataSize / type->getElementSizeBytes(); - - // Read in all of our allocation data - alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize); + if (dataSize == type->getSizeBytes()) { + uint32_t count = dataSize / type->getElementSizeBytes(); + // Read in all of our allocation data + alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize); + } else { + alloc->unpackVec3Allocation(stream->getPtr() + stream->getPos(), dataSize); + } stream->reset(stream->getPos() + dataSize); return alloc; @@ -429,13 +520,13 @@ void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t } void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face, - const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped + const void *data, size_t sizeBytes, size_t eoff) { Allocation *a = static_cast<Allocation *>(va); a->elementData(rsc, x, y, data, eoff, sizeBytes); } void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod, - const void *data, size_t eoff, uint32_t sizeBytes) { // TODO: this seems wrong, eoff and sizeBytes may be swapped + const void *data, size_t sizeBytes, size_t eoff) { Allocation *a = static_cast<Allocation *>(va); a->elementData(rsc, x, data, eoff, sizeBytes); } diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 714798a..20201ca 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2009-2012 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. @@ -80,16 +80,16 @@ public: void resize1D(Context *rsc, uint32_t dimX); void resize2D(Context *rsc, uint32_t dimX, uint32_t dimY); - void data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, uint32_t sizeBytes); + void data(Context *rsc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, size_t sizeBytes); void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, - uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes); + uint32_t w, uint32_t h, const void *data, size_t sizeBytes); void data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, RsAllocationCubemapFace face, - uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); + uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes); void elementData(Context *rsc, uint32_t x, - const void *data, uint32_t elementOff, uint32_t sizeBytes); + const void *data, uint32_t elementOff, size_t sizeBytes); void elementData(Context *rsc, uint32_t x, uint32_t y, - const void *data, uint32_t elementOff, uint32_t sizeBytes); + const void *data, uint32_t elementOff, size_t sizeBytes); void read(void *data); @@ -135,6 +135,11 @@ protected: private: void freeChildrenUnlocked(); Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc); + + uint32_t getPackedSize() const; + static void writePackedData(const Type *type, uint8_t *dst, const uint8_t *src, bool dstPadded); + void unpackVec3Allocation(const void *data, size_t dataSize); + void packVec3Allocation(OStream *stream) const; }; } diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp index 7d9cf0b..21b98f6 100644 --- a/libs/rs/rsComponent.cpp +++ b/libs/rs/rsComponent.cpp @@ -169,7 +169,8 @@ void Component::set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize) { break; } - mBits = mTypeBits * mVectorSize; + mBitsUnpadded = mTypeBits * mVectorSize; + mBits = mTypeBits * rsHigherPow2(mVectorSize); } bool Component::isReference() const { diff --git a/libs/rs/rsComponent.h b/libs/rs/rsComponent.h index 6ddc990..8629d0d 100644 --- a/libs/rs/rsComponent.h +++ b/libs/rs/rsComponent.h @@ -41,6 +41,7 @@ public: bool getIsFloat() const {return mIsFloat;} bool getIsSigned() const {return mIsSigned;} uint32_t getBits() const {return mBits;} + uint32_t getBitsUnpadded() const {return mBitsUnpadded;} // Helpers for reading / writing this class out void serialize(OStream *stream) const; @@ -56,6 +57,7 @@ protected: // derived uint32_t mBits; + uint32_t mBitsUnpadded; uint32_t mTypeBits; bool mIsFloat; bool mIsSigned; diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 54fe529..ad2ff0f 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -472,6 +472,30 @@ void Context::setSurface(uint32_t w, uint32_t h, RsNativeWindow sur) { } } +uint32_t Context::getCurrentSurfaceWidth() const { + for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) { + if (mFBOCache.mHal.state.colorTargets[i] != NULL) { + return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimX(); + } + } + if (mFBOCache.mHal.state.depthTarget != NULL) { + return mFBOCache.mHal.state.depthTarget->getType()->getDimX(); + } + return mWidth; +} + +uint32_t Context::getCurrentSurfaceHeight() const { + for (uint32_t i = 0; i < mFBOCache.mHal.state.colorTargetsCount; i ++) { + if (mFBOCache.mHal.state.colorTargets[i] != NULL) { + return mFBOCache.mHal.state.colorTargets[i]->getType()->getDimY(); + } + } + if (mFBOCache.mHal.state.depthTarget != NULL) { + return mFBOCache.mHal.state.depthTarget->getType()->getDimY(); + } + return mHeight; +} + void Context::pause() { rsAssert(mIsGraphicsContext); mPaused = true; diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h index 35221e0..61c29f9 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/rsContext.h @@ -164,6 +164,9 @@ public: uint32_t getWidth() const {return mWidth;} uint32_t getHeight() const {return mHeight;} + uint32_t getCurrentSurfaceWidth() const; + uint32_t getCurrentSurfaceHeight() const; + mutable ThreadIO mIO; // Timers diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp index b65f380..dff9585 100644 --- a/libs/rs/rsElement.cpp +++ b/libs/rs/rsElement.cpp @@ -23,6 +23,7 @@ using namespace android::renderscript; Element::Element(Context *rsc) : ObjectBase(rsc) { mBits = 0; + mBitsUnpadded = 0; mFields = NULL; mFieldCount = 0; mHasReference = false; @@ -60,6 +61,18 @@ size_t Element::getSizeBits() const { return total; } +size_t Element::getSizeBitsUnpadded() const { + if (!mFieldCount) { + return mBitsUnpadded; + } + + size_t total = 0; + for (size_t ct=0; ct < mFieldCount; ct++) { + total += mFields[ct].e->mBitsUnpadded * mFields[ct].arraySize; + } + return total; +} + void Element::dumpLOGV(const char *prefix) const { ObjectBase::dumpLOGV(prefix); ALOGV("%s Element: fieldCount: %zu, size bytes: %zu", prefix, mFieldCount, getSizeBytes()); @@ -146,14 +159,18 @@ Element *Element::createFromStream(Context *rsc, IStream *stream) { void Element::compute() { if (mFieldCount == 0) { mBits = mComponent.getBits(); + mBitsUnpadded = mComponent.getBitsUnpadded(); mHasReference = mComponent.isReference(); return; } size_t bits = 0; + size_t bitsUnpadded = 0; for (size_t ct=0; ct < mFieldCount; ct++) { mFields[ct].offsetBits = bits; + mFields[ct].offsetBitsUnpadded = bitsUnpadded; bits += mFields[ct].e->getSizeBits() * mFields[ct].arraySize; + bitsUnpadded += mFields[ct].e->getSizeBitsUnpadded() * mFields[ct].arraySize; if (mFields[ct].e->mHasReference) { mHasReference = true; diff --git a/libs/rs/rsElement.h b/libs/rs/rsElement.h index bfdec53..04010fa 100644 --- a/libs/rs/rsElement.h +++ b/libs/rs/rsElement.h @@ -43,6 +43,11 @@ public: uint32_t getGLType() const; uint32_t getGLFormat() const; + size_t getSizeBitsUnpadded() const; + size_t getSizeBytesUnpadded() const { + return (getSizeBitsUnpadded() + 7) >> 3; + } + size_t getSizeBits() const; size_t getSizeBytes() const { return (getSizeBits() + 7) >> 3; @@ -55,6 +60,10 @@ public: return mFields[componentNumber].offsetBits >> 3; } + size_t getFieldOffsetBytesUnpadded(uint32_t componentNumber) const { + return mFields[componentNumber].offsetBitsUnpadded >> 3; + } + uint32_t getFieldCount() const {return mFieldCount;} const Element * getField(uint32_t idx) const {return mFields[idx].e.get();} const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();} @@ -64,6 +73,7 @@ public: RsDataType getType() const {return mComponent.getType();} RsDataKind getKind() const {return mComponent.getKind();} uint32_t getBits() const {return mBits;} + uint32_t getBitsUnpadded() const {return mBitsUnpadded;} void dumpLOGV(const char *prefix) const; virtual void serialize(OStream *stream) const; @@ -112,6 +122,7 @@ protected: String8 name; ObjectBaseRef<const Element> e; uint32_t offsetBits; + uint32_t offsetBitsUnpadded; uint32_t arraySize; } ElementField_t; ElementField_t *mFields; @@ -123,6 +134,7 @@ protected: Element(Context *); Component mComponent; + uint32_t mBitsUnpadded; uint32_t mBits; void compute(); diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index e09f81c..4f21b3b 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -651,14 +651,10 @@ void FontState::appendMeshQuad(float x1, float y1, float z1, float x4, float y4, float z4, float u4, float v4) { const uint32_t vertsPerQuad = 4; - const uint32_t floatsPerVert = 5; + const uint32_t floatsPerVert = 6; float *currentPos = mTextMeshPtr + mCurrentQuadIndex * vertsPerQuad * floatsPerVert; - // Cull things that are off the screen - float width = (float)mRSC->getWidth(); - float height = (float)mRSC->getHeight(); - - if (x1 > width || y1 < 0.0f || x2 < 0 || y4 > height) { + if (x1 > mSurfaceWidth || y1 < 0.0f || x2 < 0 || y4 > mSurfaceHeight) { return; } @@ -670,24 +666,28 @@ void FontState::appendMeshQuad(float x1, float y1, float z1, (*currentPos++) = x1; (*currentPos++) = y1; (*currentPos++) = z1; + (*currentPos++) = 0; (*currentPos++) = u1; (*currentPos++) = v1; (*currentPos++) = x2; (*currentPos++) = y2; (*currentPos++) = z2; + (*currentPos++) = 0; (*currentPos++) = u2; (*currentPos++) = v2; (*currentPos++) = x3; (*currentPos++) = y3; (*currentPos++) = z3; + (*currentPos++) = 0; (*currentPos++) = u3; (*currentPos++) = v3; (*currentPos++) = x4; (*currentPos++) = y4; (*currentPos++) = z4; + (*currentPos++) = 0; (*currentPos++) = u4; (*currentPos++) = v4; @@ -746,6 +746,10 @@ void FontState::renderText(const char *text, uint32_t len, int32_t x, int32_t y, return; } + // Cull things that are off the screen + mSurfaceWidth = (float)mRSC->getCurrentSurfaceWidth(); + mSurfaceHeight = (float)mRSC->getCurrentSurfaceHeight(); + currentFont->renderUTF(text, len, x, y, startIndex, numGlyphs, mode, bounds, bitmap, bitmapW, bitmapH); diff --git a/libs/rs/rsFont.h b/libs/rs/rsFont.h index 679591c..4ca794d 100644 --- a/libs/rs/rsFont.h +++ b/libs/rs/rsFont.h @@ -160,6 +160,9 @@ public: protected: + float mSurfaceWidth; + float mSurfaceHeight; + friend class Font; struct CacheTextureLine { diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index 4a13622..871caac 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -206,8 +206,11 @@ void ProgramVertexState::init(Context *rsc) { void ProgramVertexState::updateSize(Context *rsc) { float *f = static_cast<float *>(mDefaultAlloc->getPtr()); + float surfaceWidth = (float)rsc->getCurrentSurfaceWidth(); + float surfaceHeight = (float)rsc->getCurrentSurfaceHeight(); + Matrix4x4 m; - m.loadOrtho(0,rsc->getWidth(), rsc->getHeight(),0, -1,1); + m.loadOrtho(0, surfaceWidth, surfaceHeight, 0, -1, 1); memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m.m, sizeof(m)); memcpy(&f[RS_PROGRAM_VERTEX_MVP_OFFSET], m.m, sizeof(m)); diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp index fad9c08..357dbe3 100644 --- a/libs/rs/rsScript.cpp +++ b/libs/rs/rsScript.cpp @@ -15,6 +15,7 @@ */ #include "rsContext.h" +#include <time.h> using namespace android; using namespace android::renderscript; @@ -25,6 +26,7 @@ Script::Script(Context *rsc) : ObjectBase(rsc) { mSlots = NULL; mTypes = NULL; + mInitialized = false; } Script::~Script() { @@ -89,8 +91,22 @@ void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint3 } void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) { - Script *s = static_cast<Script *>(vs); - s->mEnviroment.mTimeZone = timeZone; + // We unfortunately need to make a new copy of the string, since it is + // not NULL-terminated. We then use setenv(), which properly handles + // freeing/duplicating the actual string for the environment. + char *tz = (char *) malloc(length + 1); + if (!tz) { + ALOGE("Couldn't allocate memory for timezone buffer"); + return; + } + strncpy(tz, timeZone, length); + tz[length] = '\0'; + if (setenv("TZ", tz, 1) == 0) { + tzset(); + } else { + ALOGE("Error setting timezone"); + } + free(tz); } void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot, diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h index d645421..99dceaf 100644 --- a/libs/rs/rsScript.h +++ b/libs/rs/rsScript.h @@ -59,7 +59,6 @@ public: struct Enviroment_t { int64_t mStartTimeMillis; int64_t mLastDtTime; - const char* mTimeZone; ObjectBaseRef<ProgramVertex> mVertex; ObjectBaseRef<ProgramFragment> mFragment; @@ -68,7 +67,6 @@ public: }; Enviroment_t mEnviroment; - void initSlots(); void setSlot(uint32_t slot, Allocation *a); void setVar(uint32_t slot, const void *val, size_t len); void setVarObj(uint32_t slot, ObjectBase *val); @@ -86,6 +84,7 @@ public: virtual void setupScript(Context *rsc) = 0; virtual uint32_t run(Context *) = 0; protected: + bool mInitialized; ObjectBaseRef<Allocation> *mSlots; ObjectBaseRef<const Type> *mTypes; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index 5079b63..b4eb995 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -45,8 +45,10 @@ ScriptC::~ScriptC() { BT = NULL; } #endif - mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this); - mRSC->mHal.funcs.script.destroy(mRSC, this); + if (mInitialized) { + mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this); + mRSC->mHal.funcs.script.destroy(mRSC, this); + } } void ScriptC::setupScript(Context *rsc) { @@ -204,7 +206,6 @@ bool ScriptC::runCompiler(Context *rsc, return false; } - rsAssert(bcWrapper.getHeaderVersion() == 0); if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) { sdkVersion = bcWrapper.getTargetAPI(); } @@ -230,8 +231,11 @@ bool ScriptC::runCompiler(Context *rsc, bitcodeLen = BT->getTranslatedBitcodeSize(); #endif - rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0); + if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) { + return false; + } + mInitialized = true; mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); @@ -318,7 +322,7 @@ RsScript rsi_ScriptCCreate(Context *rsc, if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) { // Error during compile, destroy s and return null. - delete s; + ObjectBase::checkDelete(s); return NULL; } diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp index a7ba7d2..7964792 100644 --- a/libs/rs/rsScriptC_LibGL.cpp +++ b/libs/rs/rsScriptC_LibGL.cpp @@ -79,23 +79,28 @@ void rsrBindProgramRaster(Context *rsc, Script *sc, ProgramRaster *pr) { void rsrBindFrameBufferObjectColorTarget(Context *rsc, Script *sc, Allocation *a, uint32_t slot) { CHECK_OBJ(va); rsc->mFBOCache.bindColorTarget(rsc, a, slot); + rsc->mStateVertex.updateSize(rsc); } void rsrBindFrameBufferObjectDepthTarget(Context *rsc, Script *sc, Allocation *a) { CHECK_OBJ(va); rsc->mFBOCache.bindDepthTarget(rsc, a); + rsc->mStateVertex.updateSize(rsc); } void rsrClearFrameBufferObjectColorTarget(Context *rsc, Script *sc, uint32_t slot) { rsc->mFBOCache.bindColorTarget(rsc, NULL, slot); + rsc->mStateVertex.updateSize(rsc); } void rsrClearFrameBufferObjectDepthTarget(Context *rsc, Script *sc) { rsc->mFBOCache.bindDepthTarget(rsc, NULL); + rsc->mStateVertex.updateSize(rsc); } void rsrClearFrameBufferObjectTargets(Context *rsc, Script *sc) { rsc->mFBOCache.resetAll(rsc); + rsc->mStateVertex.updateSize(rsc); } ////////////////////////////////////////////////////////////////////////////// diff --git a/libs/rs/rsThreadIO.cpp b/libs/rs/rsThreadIO.cpp index 8ba1a0e..1917774 100644 --- a/libs/rs/rsThreadIO.cpp +++ b/libs/rs/rsThreadIO.cpp @@ -124,7 +124,6 @@ bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand, uint64_t time while (!mToCore.isEmpty() || waitForCommand) { uint32_t cmdID = 0; uint32_t cmdSize = 0; - ret = true; if (con->props.mLogTimes) { con->timerSet(Context::RS_TIMER_IDLE); } @@ -136,11 +135,17 @@ bool ThreadIO::playCoreCommands(Context *con, bool waitForCommand, uint64_t time delay = 0; } } + + if (delay == 0 && timeToWait != 0 && mToCore.isEmpty()) { + break; + } + const void * data = mToCore.get(&cmdID, &cmdSize, delay); if (!cmdSize) { // exception or timeout occurred. - return false; + break; } + ret = true; if (con->props.mLogTimes) { con->timerSet(Context::RS_TIMER_INTERNAL); } diff --git a/libs/rs/scriptc/rs_atomic.rsh b/libs/rs/scriptc/rs_atomic.rsh index 87c6c02..a455edd 100644 --- a/libs/rs/scriptc/rs_atomic.rsh +++ b/libs/rs/scriptc/rs_atomic.rsh @@ -242,7 +242,7 @@ extern int32_t __attribute__((overloadable)) * @return old value */ extern uint32_t __attribute__((overloadable)) - rsAtomicCas(volatile uint32_t* addr, int32_t compareValue, int32_t newValue); + rsAtomicCas(volatile uint32_t* addr, uint32_t compareValue, uint32_t newValue); #endif //defined(RS_VERSION) && (RS_VERSION >= 14) diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh index e9c3c5e..84bca9c 100644 --- a/libs/rs/scriptc/rs_types.rsh +++ b/libs/rs/scriptc/rs_types.rsh @@ -364,7 +364,7 @@ typedef struct { typedef float4 rs_quaternion; #define RS_PACKED __attribute__((packed, aligned(4))) -#define NULL ((const void *)0) +#define NULL ((void *)0) #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |