diff options
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/driver/rsdBcc.cpp | 24 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 111 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.h | 5 | ||||
-rw-r--r-- | libs/rs/rsAllocation.cpp | 27 | ||||
-rw-r--r-- | libs/rs/rsAllocation.h | 2 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 1 | ||||
-rw-r--r-- | libs/rs/rsObjectBase.cpp | 26 | ||||
-rw-r--r-- | libs/rs/rsObjectBase.h | 2 | ||||
-rw-r--r-- | libs/rs/rsProgram.cpp | 21 | ||||
-rw-r--r-- | libs/rs/rsProgram.h | 1 |
10 files changed, 195 insertions, 25 deletions
diff --git a/libs/rs/driver/rsdBcc.cpp b/libs/rs/driver/rsdBcc.cpp index 176dd18..44ea79c 100644 --- a/libs/rs/driver/rsdBcc.cpp +++ b/libs/rs/driver/rsdBcc.cpp @@ -45,6 +45,7 @@ struct DrvScript { InvokeFunc_t *mInvokeFunctions; void ** mFieldAddress; bool * mFieldIsObject; + const uint32_t *mExportForEachSignatureList; const uint8_t * mScriptText; uint32_t mScriptTextLength; @@ -74,6 +75,7 @@ bool rsdScriptInit(const Context *rsc, size_t exportFuncCount = 0; size_t exportVarCount = 0; size_t objectSlotCount = 0; + size_t exportForEachSignatureCount = 0; DrvScript *drv = (DrvScript *)calloc(1, sizeof(DrvScript)); if (drv == NULL) { @@ -153,6 +155,10 @@ bool rsdScriptInit(const Context *rsc, } } + exportForEachSignatureCount = drv->ME->getExportForEachSignatureCount(); + rsAssert(exportForEachSignatureCount <= 1); + drv->mExportForEachSignatureList = drv->ME->getExportForEachSignatureList(); + // Copy info over to runtime script->mHal.info.exportedFunctionCount = drv->ME->getExportFuncCount(); script->mHal.info.exportedVariableCount = drv->ME->getExportVarCount(); @@ -179,6 +185,7 @@ error: typedef struct { Context *rsc; Script *script; + uint32_t sig; const Allocation * ain; Allocation * aout; const void * usr; @@ -206,7 +213,7 @@ typedef struct { uint32_t dimZ; uint32_t dimArray; } MTLaunchStruct; -typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t); +typedef void (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t); static void wc_xy(void *usr, uint32_t idx) { MTLaunchStruct *mtls = (MTLaunchStruct *)usr; @@ -214,6 +221,8 @@ static void wc_xy(void *usr, uint32_t idx) { memset(&p, 0, sizeof(p)); p.usr = mtls->usr; p.usr_len = mtls->usrLen; + RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv; + uint32_t sig = mtls->sig; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); @@ -234,7 +243,7 @@ static void wc_xy(void *usr, uint32_t idx) { for (p.x = mtls->xStart; p.x < mtls->xEnd; p.x++) { p.in = xPtrIn; p.out = xPtrOut; - ((rs_t)mtls->script->mHal.info.root) (p.in, p.out, p.usr, p.x, p.y, 0, 0); + dc->mForEachLaunch[sig](&mtls->script->mHal.info.root, &p); xPtrIn += mtls->eStrideIn; xPtrOut += mtls->eStrideOut; } @@ -248,6 +257,8 @@ static void wc_x(void *usr, uint32_t idx) { memset(&p, 0, sizeof(p)); p.usr = mtls->usr; p.usr_len = mtls->usrLen; + RsdHal * dc = (RsdHal *)mtls->rsc->mHal.drv; + uint32_t sig = mtls->sig; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); @@ -265,7 +276,7 @@ static void wc_x(void *usr, uint32_t idx) { for (p.x = xStart; p.x < xEnd; p.x++) { p.in = xPtrIn; p.out = xPtrOut; - ((rs_t)mtls->script->mHal.info.root) (p.in, p.out, p.usr, p.x, 0, 0, 0); + dc->mForEachLaunch[sig](&mtls->script->mHal.info.root, &p); xPtrIn += mtls->eStrideIn; xPtrOut += mtls->eStrideOut; } @@ -286,6 +297,10 @@ void rsdScriptInvokeForEach(const Context *rsc, MTLaunchStruct mtls; memset(&mtls, 0, sizeof(mtls)); + DrvScript *drv = (DrvScript *)s->mHal.drv; + // We only support slot 0 (root) at this point in time. + rsAssert(slot == 0); + mtls.sig = drv->mExportForEachSignatureList[slot]; if (ain) { mtls.dimX = ain->getType()->getDimX(); mtls.dimY = ain->getType()->getDimY(); @@ -369,6 +384,7 @@ void rsdScriptInvokeForEach(const Context *rsc, memset(&p, 0, sizeof(p)); p.usr = mtls.usr; p.usr_len = mtls.usrLen; + uint32_t sig = mtls.sig; //LOGE("launch 3"); for (p.ar[0] = mtls.arrayStart; p.ar[0] < mtls.arrayEnd; p.ar[0]++) { @@ -383,7 +399,7 @@ void rsdScriptInvokeForEach(const Context *rsc, for (p.x = mtls.xStart; p.x < mtls.xEnd; p.x++) { p.in = xPtrIn; p.out = xPtrOut; - ((rs_t)s->mHal.info.root) (p.in, p.out, p.usr, p.x, p.y, p.z, p.ar[0]); + dc->mForEachLaunch[sig](&s->mHal.info.root, &p); xPtrIn += mtls.eStrideIn; xPtrOut += mtls.eStrideOut; } diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index 38f6895..171d045 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -43,6 +43,7 @@ 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, @@ -206,6 +207,8 @@ 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); @@ -287,4 +290,112 @@ void Shutdown(Context *rsc) { } +static void rsdForEach17(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(const void *, uint32_t); + (*(fe*)vRoot)(p->in, p->y); +} + +static void rsdForEach18(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(void *, uint32_t); + (*(fe*)vRoot)(p->out, p->y); +} + +static void rsdForEach19(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + 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) { + 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) { + 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) { + 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) { + typedef void (*fe)(const void *, uint32_t, uint32_t); + (*(fe*)vRoot)(p->in, p->x, p->y); +} + +static void rsdForEach26(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(void *, uint32_t, uint32_t); + (*(fe*)vRoot)(p->out, p->x, p->y); +} + +static void rsdForEach27(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(const void *, void *, uint32_t, uint32_t); + (*(fe*)vRoot)(p->in, p->out, p->x, p->y); +} + +static void rsdForEach29(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(const void *, const void *, uint32_t, uint32_t); + (*(fe*)vRoot)(p->in, p->usr, p->x, p->y); +} + +static void rsdForEach30(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(void *, const void *, uint32_t, uint32_t); + (*(fe*)vRoot)(p->out, p->usr, p->x, p->y); +} + +static void rsdForEach31(const void *vRoot, + const android::renderscript::RsForEachStubParamStruct *p) { + typedef void (*fe)(const void *, void *, const void *, uint32_t, uint32_t); + (*(fe*)vRoot)(p->in, p->out, p->usr, p->x, p->y); +} + + +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 f393b60..159b72a 100644 --- a/libs/rs/driver/rsdCore.h +++ b/libs/rs/driver/rsdCore.h @@ -27,6 +27,9 @@ 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 *); + typedef struct RsdSymbolTableRec { const char * mName; void * mPtr; @@ -57,6 +60,8 @@ typedef struct RsdHalRec { Workers mWorkers; bool mExit; + outer_foreach_t mForEachLaunch[32]; + ScriptTLSStruct mTlsStruct; RsdGL gl; diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index a366d49..4359d95 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -58,19 +58,7 @@ void Allocation::updateCache() { } Allocation::~Allocation() { - if (mHal.state.hasReferences && - (mHal.state.hasFaces || mHal.state.hasMipmaps)) { - LOGE("Cube/mip allocation with references unsupported, memory not cleaned up!"); - } - - uint32_t elemCount = mHal.state.dimensionX; - if (mHal.state.dimensionY > 1) { - elemCount *= mHal.state.dimensionY; - } - if (mHal.state.dimensionZ > 1) { - elemCount *= mHal.state.dimensionZ; - } - decRefs(getPtr(), elemCount, 0); + freeChildrenUnlocked(); mRSC->mHal.funcs.allocation.destroy(mRSC, this); } @@ -299,6 +287,19 @@ void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const { } } +void Allocation::freeChildrenUnlocked () { + decRefs(getPtr(), mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0); +} + +bool Allocation::freeChildren() { + if (mHal.state.hasReferences) { + incSysRef(); + freeChildrenUnlocked(); + return decSysRef(); + } + return false; +} + void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) { } diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index f2589c0..67fc3b5 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -116,6 +116,7 @@ public: void incRefs(const void *ptr, size_t ct, size_t startOff = 0) const; void decRefs(const void *ptr, size_t ct, size_t startOff = 0) const; + virtual bool freeChildren(); void sendDirty(const Context *rsc) const; bool getHasGraphicsMipmaps() const { @@ -127,6 +128,7 @@ protected: Vector<const Program *> mToDirtyList; private: + void freeChildrenUnlocked(); Allocation(Context *rsc, const Type *, uint32_t usages, RsAllocationMipmapControl mc); }; diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 8996ad1..e3a9cf8 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -312,6 +312,7 @@ void Context::destroyWorkerThreadResources() { mStateSampler.deinit(this); mFBOCache.deinit(this); } + ObjectBase::freeAllChildren(this); //LOGV("destroyWorkerThreadResources 2"); mExit = true; } diff --git a/libs/rs/rsObjectBase.cpp b/libs/rs/rsObjectBase.cpp index f428f94..f5ced26 100644 --- a/libs/rs/rsObjectBase.cpp +++ b/libs/rs/rsObjectBase.cpp @@ -81,6 +81,10 @@ void ObjectBase::incSysRef() const { void ObjectBase::preDestroy() const { } +bool ObjectBase::freeChildren() { + return false; +} + bool ObjectBase::checkDelete(const ObjectBase *ref) { if (!ref) { return false; @@ -217,6 +221,28 @@ void ObjectBase::zeroAllUserRef(Context *rsc) { } } +void ObjectBase::freeAllChildren(Context *rsc) { + if (rsc->props.mLogObjects) { + LOGV("Forcing release of all child objects."); + } + + // This operation can be slow, only to be called during context cleanup. + ObjectBase * o = (ObjectBase *)rsc->mObjHead; + while (o) { + if (o->freeChildren()) { + // deleted ref to self and possibly others, restart from head. + o = (ObjectBase *)rsc->mObjHead; + } else { + o = (ObjectBase *)o->mNext; + } + } + + if (rsc->props.mLogObjects) { + LOGV("Objects remaining."); + dumpAll(rsc); + } +} + void ObjectBase::dumpAll(Context *rsc) { asyncLock(); diff --git a/libs/rs/rsObjectBase.h b/libs/rs/rsObjectBase.h index c7cfb0e..d9f5f3b 100644 --- a/libs/rs/rsObjectBase.h +++ b/libs/rs/rsObjectBase.h @@ -50,8 +50,10 @@ public: void setName(const char *, uint32_t len); Context * getContext() const {return mRSC;} + virtual bool freeChildren(); static void zeroAllUserRef(Context *rsc); + static void freeAllChildren(Context *rsc); static void dumpAll(Context *rsc); virtual void dumpLOGV(const char *prefix) const; diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index 33eb422..4178aa5 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -70,15 +70,8 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, } Program::~Program() { + freeChildren(); - for (uint32_t ct=0; ct < mHal.state.constantsCount; ct++) { - bindAllocation(NULL, NULL, ct); - } - - for (uint32_t ct=0; ct < mHal.state.texturesCount; ct++) { - bindTexture(NULL, ct, NULL); - bindSampler(NULL, ct, NULL); - } delete[] mHal.state.textures; delete[] mHal.state.samplers; delete[] mHal.state.textureTargets; @@ -90,6 +83,18 @@ Program::~Program() { mHal.state.texturesCount = 0; } +bool Program::freeChildren() { + for (uint32_t ct=0; ct < mHal.state.constantsCount; ct++) { + bindAllocation(NULL, NULL, ct); + } + + for (uint32_t ct=0; ct < mHal.state.texturesCount; ct++) { + bindTexture(NULL, ct, NULL); + bindSampler(NULL, ct, NULL); + } + return false; +} + void Program::initMemberVars() { mDirty = true; diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h index 948ba3e..3237a72 100644 --- a/libs/rs/rsProgram.h +++ b/libs/rs/rsProgram.h @@ -34,6 +34,7 @@ public: Program(Context *, const char * shaderText, uint32_t shaderLength, const uint32_t * params, uint32_t paramLength); virtual ~Program(); + virtual bool freeChildren(); void bindAllocation(Context *, Allocation *, uint32_t slot); |