diff options
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/RenderScript.h | 12 | ||||
-rw-r--r-- | libs/rs/driver/rsdBcc.cpp | 46 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.cpp | 97 | ||||
-rw-r--r-- | libs/rs/driver/rsdCore.h | 4 | ||||
-rw-r--r-- | libs/rs/driver/rsdFrameBuffer.cpp | 12 | ||||
-rw-r--r-- | libs/rs/driver/rsdMeshObj.cpp | 9 | ||||
-rw-r--r-- | libs/rs/driver/rsdProgram.cpp | 2 | ||||
-rw-r--r-- | libs/rs/driver/rsdShader.cpp | 18 | ||||
-rw-r--r-- | libs/rs/rsAllocation.cpp | 8 | ||||
-rw-r--r-- | libs/rs/rsAllocation.h | 9 | ||||
-rw-r--r-- | libs/rs/rsElement.cpp | 3 | ||||
-rw-r--r-- | libs/rs/rsFBOCache.cpp | 17 | ||||
-rw-r--r-- | libs/rs/rsFBOCache.h | 6 | ||||
-rw-r--r-- | libs/rs/rsMesh.cpp | 69 | ||||
-rw-r--r-- | libs/rs/rsMesh.h | 24 | ||||
-rw-r--r-- | libs/rs/rsProgram.cpp | 55 | ||||
-rw-r--r-- | libs/rs/rsProgram.h | 41 | ||||
-rw-r--r-- | libs/rs/rsProgramFragment.cpp | 4 | ||||
-rw-r--r-- | libs/rs/rsProgramRaster.h | 25 | ||||
-rw-r--r-- | libs/rs/rsProgramStore.h | 35 | ||||
-rw-r--r-- | libs/rs/rsProgramVertex.cpp | 10 | ||||
-rw-r--r-- | libs/rs/rsSampler.h | 37 | ||||
-rw-r--r-- | libs/rs/rsScriptC.cpp | 20 | ||||
-rw-r--r-- | libs/rs/scriptc/rs_allocation.rsh | 25 | ||||
-rw-r--r-- | libs/rs/scriptc/rs_graphics.rsh | 1 | ||||
-rw-r--r-- | libs/rs/scriptc/rs_quaternion.rsh | 78 |
26 files changed, 415 insertions, 252 deletions
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 3ba0123..6d54268 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -34,26 +34,30 @@ RsFile rsaFileA3DCreateFromMemory(RsContext, const void *data, uint32_t len); RsFile rsaFileA3DCreateFromAsset(RsContext, void *asset); RsFile rsaFileA3DCreateFromFile(RsContext, const char *path); void rsaFileA3DGetNumIndexEntries(RsContext, int32_t *numEntries, RsFile); -void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries,uint32_t numEntries, RsFile); +void rsaFileA3DGetIndexEntries(RsContext, RsFileIndexEntry *fileEntries, + uint32_t numEntries, RsFile); void rsaGetName(RsContext, void * obj, const char **name); // Mesh update functions void rsaMeshGetVertexBufferCount(RsContext, RsMesh, int32_t *vtxCount); void rsaMeshGetIndexCount(RsContext, RsMesh, int32_t *idxCount); void rsaMeshGetVertices(RsContext, RsMesh, RsAllocation *vtxData, uint32_t vtxDataCount); -void rsaMeshGetIndices(RsContext, RsMesh, RsAllocation *va, uint32_t *primType, uint32_t idxDataCount); +void rsaMeshGetIndices(RsContext, RsMesh, RsAllocation *va, + uint32_t *primType, uint32_t idxDataCount); // Allocation update const void* rsaAllocationGetType(RsContext con, RsAllocation va); // Type update void rsaTypeGetNativeData(RsContext, RsType, uint32_t *typeData, uint32_t typeDataSize); // Element update void rsaElementGetNativeData(RsContext, RsElement, uint32_t *elemData, uint32_t elemDataSize); -void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, uint32_t dataSize); +void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, + uint32_t *arraySizes, uint32_t dataSize); RsDevice rsDeviceCreate(); void rsDeviceDestroy(RsDevice dev); void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value); RsContext rsContextCreate(RsDevice dev, uint32_t version, uint32_t sdkVersion); -RsContext rsContextCreateGL(RsDevice dev, uint32_t version, uint32_t sdkVersion, RsSurfaceConfig sc, uint32_t dpi); +RsContext rsContextCreateGL(RsDevice dev, uint32_t version, uint32_t sdkVersion, + RsSurfaceConfig sc, uint32_t dpi); #include "rsgApiFuncDecl.h" diff --git a/libs/rs/driver/rsdBcc.cpp b/libs/rs/driver/rsdBcc.cpp index 5fd5c35..4ecf8e8 100644 --- a/libs/rs/driver/rsdBcc.cpp +++ b/libs/rs/driver/rsdBcc.cpp @@ -226,6 +226,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]; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize; @@ -239,16 +240,10 @@ static void wc_xy(void *usr, uint32_t idx) { //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); for (p.y = yStart; p.y < yEnd; p.y++) { uint32_t offset = mtls->dimX * p.y; - uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset); - const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset); - - for (p.x = mtls->xStart; p.x < mtls->xEnd; p.x++) { - p.in = xPtrIn; - p.out = xPtrOut; - dc->mForEachLaunch[sig](&mtls->script->mHal.info.root, &p); - xPtrIn += mtls->eStrideIn; - xPtrOut += mtls->eStrideOut; - } + 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); } } } @@ -262,6 +257,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]; while (1) { uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize; @@ -271,17 +267,12 @@ static void wc_x(void *usr, uint32_t idx) { return; } - //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd); + //LOGE("usr slice %i idx %i, x %i,%i", slice, idx, xStart, xEnd); //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); - uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * xStart); - const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * xStart); - for (p.x = xStart; p.x < xEnd; p.x++) { - p.in = xPtrIn; - p.out = xPtrOut; - dc->mForEachLaunch[sig](&mtls->script->mHal.info.root, &p); - xPtrIn += mtls->eStrideIn; - xPtrOut += mtls->eStrideOut; - } + + 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); } } @@ -392,22 +383,17 @@ void rsdScriptInvokeForEach(const Context *rsc, uint32_t sig = mtls.sig; //LOGE("launch 3"); + outer_foreach_t fn = dc->mForEachLaunch[sig]; 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++) { uint32_t offset = mtls.dimX * mtls.dimY * mtls.dimZ * p.ar[0] + mtls.dimX * mtls.dimY * p.z + mtls.dimX * p.y; - uint8_t *xPtrOut = mtls.ptrOut + (mtls.eStrideOut * offset); - const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset); - - for (p.x = mtls.xStart; p.x < mtls.xEnd; p.x++) { - p.in = xPtrIn; - p.out = xPtrOut; - dc->mForEachLaunch[sig](&s->mHal.info.root, &p); - xPtrIn += mtls.eStrideIn; - xPtrOut += mtls.eStrideOut; - } + 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); } } } diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index f8107d9..247f4dc 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -292,75 +292,136 @@ void Shutdown(Context *rsc) { } static void rsdForEach17(const void *vRoot, - const android::renderscript::RsForEachStubParamStruct *p) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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); - (*(fe*)vRoot)(p->in, p->x, p->y); + 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) { + 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); - (*(fe*)vRoot)(p->out, p->x, p->y); + 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) { + 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); - (*(fe*)vRoot)(p->in, p->out, p->x, p->y); + 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) { + 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); - (*(fe*)vRoot)(p->in, p->usr, p->x, p->y); + 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) { + 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); - (*(fe*)vRoot)(p->out, p->usr, p->x, p->y); + 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) { + 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); - (*(fe*)vRoot)(p->in, p->out, p->usr, p->x, p->y); + 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; + } } diff --git a/libs/rs/driver/rsdCore.h b/libs/rs/driver/rsdCore.h index 159b72a..ce86d11 100644 --- a/libs/rs/driver/rsdCore.h +++ b/libs/rs/driver/rsdCore.h @@ -28,7 +28,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 *); + const android::renderscript::RsForEachStubParamStruct *, + uint32_t x1, uint32_t x2, + uint32_t instep, uint32_t outstep); typedef struct RsdSymbolTableRec { const char * mName; diff --git a/libs/rs/driver/rsdFrameBuffer.cpp b/libs/rs/driver/rsdFrameBuffer.cpp index 8c1b12d..bb07d29 100644 --- a/libs/rs/driver/rsdFrameBuffer.cpp +++ b/libs/rs/driver/rsdFrameBuffer.cpp @@ -33,11 +33,11 @@ void setDepthAttachment(const Context *rsc, const FBOCache *fb) { RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv; DrvAllocation *depth = NULL; - if (fb->mHal.state.depthTarget.get() != NULL) { + if (fb->mHal.state.depthTarget != NULL) { depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv; if (depth->uploadDeferred) { - rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget.get(), + rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget, RS_ALLOCATION_USAGE_SCRIPT); } } @@ -49,11 +49,11 @@ void setColorAttachment(const Context *rsc, const FBOCache *fb) { // Now attach color targets for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) { DrvAllocation *color = NULL; - if (fb->mHal.state.colorTargets[i].get() != NULL) { + if (fb->mHal.state.colorTargets[i] != NULL) { color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv; if (color->uploadDeferred) { - rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i].get(), + rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i], RS_ALLOCATION_USAGE_SCRIPT); } } @@ -79,10 +79,10 @@ void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) { setColorAttachment(rsc, fb); RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv; - if (fb->mHal.state.colorTargets[0].get()) { + if (fb->mHal.state.colorTargets[0]) { fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(), fb->mHal.state.colorTargets[0]->getType()->getDimY()); - } else if (fb->mHal.state.depthTarget.get()) { + } else if (fb->mHal.state.depthTarget) { fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(), fb->mHal.state.depthTarget->getType()->getDimY()); } diff --git a/libs/rs/driver/rsdMeshObj.cpp b/libs/rs/driver/rsdMeshObj.cpp index 019167b..24a7183 100644 --- a/libs/rs/driver/rsdMeshObj.cpp +++ b/libs/rs/driver/rsdMeshObj.cpp @@ -138,7 +138,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, } for (uint32_t ct=0; ct < mRSMesh->mHal.state.vertexBuffersCount; ct++) { - const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct].get(); + const Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[ct]; DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; if (drv->uploadDeferred) { rsdAllocationSyncAll(rsc, alloc, RS_ALLOCATION_USAGE_SCRIPT); @@ -148,7 +148,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, // update attributes with either buffer information or data ptr based on their current state for (uint32_t ct=0; ct < mAttribCount; ct++) { uint32_t allocIndex = mAttribAllocationIndex[ct]; - Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex].get(); + Allocation *alloc = mRSMesh->mHal.state.vertexBuffers[allocIndex]; DrvAllocation *drvAlloc = (DrvAllocation *)alloc->mHal.drv; if (drvAlloc->bufferID) { @@ -163,8 +163,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, RsdVertexArray va(mAttribs, mAttribCount); va.setup(rsc); - Mesh::Primitive_t *prim = mRSMesh->mHal.state.primitives[primIndex]; - const Allocation *idxAlloc = prim->mIndexBuffer.get(); + const Allocation *idxAlloc = mRSMesh->mHal.state.indexBuffers[primIndex]; if (idxAlloc) { DrvAllocation *drvAlloc = (DrvAllocation *)idxAlloc->mHal.drv; if (drvAlloc->uploadDeferred) { @@ -190,7 +189,7 @@ void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex, void RsdMeshObj::updateGLPrimitives() { mGLPrimitives = new uint32_t[mRSMesh->mHal.state.primitivesCount]; for (uint32_t i = 0; i < mRSMesh->mHal.state.primitivesCount; i ++) { - switch (mRSMesh->mHal.state.primitives[i]->mPrimitive) { + switch (mRSMesh->mHal.state.primitives[i]) { case RS_PRIMITIVE_POINT: mGLPrimitives[i] = GL_POINTS; break; case RS_PRIMITIVE_LINE: mGLPrimitives[i] = GL_LINES; break; case RS_PRIMITIVE_LINE_STRIP: mGLPrimitives[i] = GL_LINE_STRIP; break; diff --git a/libs/rs/driver/rsdProgram.cpp b/libs/rs/driver/rsdProgram.cpp index 27a6663..7556e50 100644 --- a/libs/rs/driver/rsdProgram.cpp +++ b/libs/rs/driver/rsdProgram.cpp @@ -43,7 +43,7 @@ bool rsdProgramVertexInit(const Context *rsc, const ProgramVertex *pv, static void SyncProgramConstants(const Context *rsc, const Program *p) { for (uint32_t ct=0; ct < p->mHal.state.texturesCount; ct++) { - const Allocation *a = p->mHal.state.textures[ct].get(); + const Allocation *a = p->mHal.state.textures[ct]; if (!a) { continue; } diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp index 16ff063..bdb60c2 100644 --- a/libs/rs/driver/rsdShader.cpp +++ b/libs/rs/driver/rsdShader.cpp @@ -69,7 +69,7 @@ void RsdShader::init() { uint32_t attribCount = 0; uint32_t uniformCount = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - initAddUserElement(mRSProgram->mHal.state.inputElements[ct].get(), mAttribNames, NULL, &attribCount, RS_SHADER_ATTR); + initAddUserElement(mRSProgram->mHal.state.inputElements[ct], mAttribNames, NULL, &attribCount, RS_SHADER_ATTR); } for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { initAddUserElement(mRSProgram->mHal.state.constantTypes[ct]->getElement(), mUniformNames, mUniformArraySizes, &uniformCount, RS_SHADER_UNI); @@ -89,7 +89,7 @@ void RsdShader::init() { String8 RsdShader::getGLSLInputString() const { String8 s; for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - const Element *e = mRSProgram->mHal.state.inputElements[ct].get(); + const Element *e = mRSProgram->mHal.state.inputElements[ct]; for (uint32_t field=0; field < e->getFieldCount(); field++) { const Element *f = e->getField(field); @@ -113,7 +113,7 @@ String8 RsdShader::getGLSLInputString() const { void RsdShader::appendAttributes() { for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - const Element *e = mRSProgram->mHal.state.inputElements[ct].get(); + const Element *e = mRSProgram->mHal.state.inputElements[ct]; for (uint32_t field=0; field < e->getFieldCount(); field++) { const Element *f = e->getField(field); const char *fn = e->getFieldName(field); @@ -414,7 +414,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { RSD_CALL_GL(glActiveTexture, GL_TEXTURE0 + ct); RSD_CALL_GL(glUniform1i, sc->fragUniformSlot(mTextureUniformIndexStart + ct), ct); - if (!mRSProgram->mHal.state.textures[ct].get()) { + if (!mRSProgram->mHal.state.textures[ct]) { // if nothing is bound, reset to default GL texture RSD_CALL_GL(glBindTexture, mTextureTargets[ct], 0); continue; @@ -427,9 +427,9 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { } RSD_CALL_GL(glBindTexture, drvTex->glTarget, drvTex->textureID); rsdGLCheckError(rsc, "ProgramFragment::setup tex bind"); - if (mRSProgram->mHal.state.samplers[ct].get()) { - setupSampler(rsc, mRSProgram->mHal.state.samplers[ct].get(), - mRSProgram->mHal.state.textures[ct].get()); + if (mRSProgram->mHal.state.samplers[ct]) { + setupSampler(rsc, mRSProgram->mHal.state.samplers[ct], + mRSProgram->mHal.state.textures[ct]); } else { RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); RSD_CALL_GL(glTexParameteri, drvTex->glTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -448,7 +448,7 @@ void RsdShader::setupTextures(const Context *rsc, RsdShaderCache *sc) { void RsdShader::setupUserConstants(const Context *rsc, RsdShaderCache *sc, bool isFragment) { uint32_t uidx = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.constantsCount; ct++) { - Allocation *alloc = mRSProgram->mHal.state.constants[ct].get(); + Allocation *alloc = mRSProgram->mHal.state.constants[ct]; if (!alloc) { LOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set", (uint32_t)this, ct); @@ -504,7 +504,7 @@ void RsdShader::setup(const android::renderscript::Context *rsc, RsdShaderCache void RsdShader::initAttribAndUniformArray() { mAttribCount = 0; for (uint32_t ct=0; ct < mRSProgram->mHal.state.inputElementsCount; ct++) { - const Element *elem = mRSProgram->mHal.state.inputElements[ct].get(); + const Element *elem = mRSProgram->mHal.state.inputElements[ct]; for (uint32_t field=0; field < elem->getFieldCount(); field++) { if (elem->getFieldName(field)[0] != '#') { mAttribCount ++; diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index 4359d95..e732630 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -30,7 +30,7 @@ Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages, mHal.state.usageFlags = usages; mHal.state.mipmapControl = mc; - mHal.state.type.set(type); + setType(type); updateCache(); } @@ -47,7 +47,7 @@ Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32 } void Allocation::updateCache() { - const Type *type = mHal.state.type.get(); + const Type *type = mHal.state.type; mHal.state.dimensionX = type->getDimX(); mHal.state.dimensionY = type->getDimY(); mHal.state.dimensionZ = type->getDimZ(); @@ -187,7 +187,7 @@ void Allocation::dumpLOGV(const char *prefix) const { String8 s(prefix); s.append(" type "); - if (mHal.state.type.get()) { + if (mHal.state.type) { mHal.state.type->dumpLOGV(s.string()); } @@ -314,7 +314,7 @@ void Allocation::resize1D(Context *rsc, uint32_t dimX) { decRefs(getPtr(), oldDimX - dimX, dimX); } rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences); - mHal.state.type.set(t.get()); + setType(t.get()); updateCache(); } diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 67fc3b5..714798a 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -41,7 +41,7 @@ public: void * drv; struct State { - ObjectBaseRef<const Type> type; + const Type * type; uint32_t usageFlags; RsAllocationMipmapControl mipmapControl; @@ -71,7 +71,7 @@ public: void updateCache(); void * getPtr() const {return mHal.drvState.mallocPtr;} - const Type * getType() const {return mHal.state.type.get();} + const Type * getType() const {return mHal.state.type;} void syncAll(Context *rsc, RsAllocationUsageType src); @@ -126,6 +126,11 @@ public: protected: Vector<const Program *> mToDirtyList; + ObjectBaseRef<const Type> mType; + void setType(const Type *t) { + mType.set(t); + mHal.state.type = t; + } private: void freeChildrenUnlocked(); diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp index d6ab0da..71e1b91 100644 --- a/libs/rs/rsElement.cpp +++ b/libs/rs/rsElement.cpp @@ -364,7 +364,7 @@ void rsaElementGetNativeData(RsContext con, RsElement elem, } void rsaElementGetSubElements(RsContext con, RsElement elem, uint32_t *ids, - const char **names, uint32_t dataSize) { + const char **names, uint32_t *arraySizes, uint32_t dataSize) { Element *e = static_cast<Element *>(elem); rsAssert(e->getFieldCount() == dataSize); @@ -372,5 +372,6 @@ void rsaElementGetSubElements(RsContext con, RsElement elem, uint32_t *ids, e->getField(i)->incUserRef(); ids[i] = (uint32_t)e->getField(i); names[i] = e->getFieldName(i); + arraySizes[i] = e->getFieldArraySize(i); } } diff --git a/libs/rs/rsFBOCache.cpp b/libs/rs/rsFBOCache.cpp index c5c64c2..f4a8bc6 100644 --- a/libs/rs/rsFBOCache.cpp +++ b/libs/rs/rsFBOCache.cpp @@ -26,11 +26,14 @@ using namespace android::renderscript; FBOCache::FBOCache() { mDirty = true; mHal.state.colorTargetsCount = 1; - mHal.state.colorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount]; + mHal.state.colorTargets = new Allocation*[mHal.state.colorTargetsCount]; + mColorTargets = new ObjectBaseRef<Allocation>[mHal.state.colorTargetsCount]; + resetAll(NULL); } FBOCache::~FBOCache() { delete[] mHal.state.colorTargets; + delete[] mColorTargets; } void FBOCache::init(Context *rsc) { @@ -52,7 +55,8 @@ void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) { return; } } - mHal.state.colorTargets[slot].set(a); + mColorTargets[slot].set(a); + mHal.state.colorTargets[slot] = a; mDirty = true; } @@ -63,15 +67,18 @@ void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) { return; } } - mHal.state.depthTarget.set(a); + mDepthTarget.set(a); + mHal.state.depthTarget = a; mDirty = true; } void FBOCache::resetAll(Context *) { for (uint32_t i = 0; i < mHal.state.colorTargetsCount; i ++) { - mHal.state.colorTargets[i].set(NULL); + mColorTargets[i].set(NULL); + mHal.state.colorTargets[i] = NULL; } - mHal.state.depthTarget.set(NULL); + mDepthTarget.set(NULL); + mHal.state.depthTarget = NULL; mDirty = true; } diff --git a/libs/rs/rsFBOCache.h b/libs/rs/rsFBOCache.h index 5d58ba4..abb84de 100644 --- a/libs/rs/rsFBOCache.h +++ b/libs/rs/rsFBOCache.h @@ -44,15 +44,17 @@ public: mutable void *drv; struct State { - ObjectBaseRef<Allocation> *colorTargets; + Allocation **colorTargets; uint32_t colorTargetsCount; - ObjectBaseRef<Allocation> depthTarget; + Allocation *depthTarget; }; State state; }; Hal mHal; protected: + ObjectBaseRef<Allocation> *mColorTargets; + ObjectBaseRef<Allocation> mDepthTarget; bool mDirty; void checkError(Context *); void setColorAttachment(Context *rsc); diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp index 359d09f..bf9284f 100644 --- a/libs/rs/rsMesh.cpp +++ b/libs/rs/rsMesh.cpp @@ -23,9 +23,14 @@ Mesh::Mesh(Context *rsc) : ObjectBase(rsc) { mHal.drv = NULL; mHal.state.primitives = NULL; mHal.state.primitivesCount = 0; + mHal.state.indexBuffers = NULL; + mHal.state.indexBuffersCount = 0; mHal.state.vertexBuffers = NULL; mHal.state.vertexBuffersCount = 0; mInitialized = false; + + mVertexBuffers = NULL; + mIndexBuffers = NULL; } Mesh::Mesh(Context *rsc, @@ -33,12 +38,23 @@ Mesh::Mesh(Context *rsc, uint32_t primitivesCount) : ObjectBase(rsc) { mHal.drv = NULL; mHal.state.primitivesCount = primitivesCount; - mHal.state.primitives = new Primitive_t *[mHal.state.primitivesCount]; + mHal.state.indexBuffersCount = primitivesCount; + mHal.state.primitives = new RsPrimitive[mHal.state.primitivesCount]; + mHal.state.indexBuffers = new Allocation *[mHal.state.indexBuffersCount]; for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) { - mHal.state.primitives[i] = new Primitive_t; + mHal.state.primitives[i] = RS_PRIMITIVE_POINT; + } + for (uint32_t i = 0; i < mHal.state.indexBuffersCount; i ++) { + mHal.state.indexBuffers[i] = NULL; } mHal.state.vertexBuffersCount = vertexBuffersCount; - mHal.state.vertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount]; + mHal.state.vertexBuffers = new Allocation *[mHal.state.vertexBuffersCount]; + for (uint32_t i = 0; i < mHal.state.vertexBuffersCount; i ++) { + mHal.state.vertexBuffers[i] = NULL; + } + + mVertexBuffers = new ObjectBaseRef<Allocation>[mHal.state.vertexBuffersCount]; + mIndexBuffers = new ObjectBaseRef<Allocation>[mHal.state.primitivesCount]; } Mesh::~Mesh() { @@ -46,17 +62,12 @@ Mesh::~Mesh() { mRSC->mHal.funcs.mesh.destroy(mRSC, this); #endif - if (mHal.state.vertexBuffers) { - delete[] mHal.state.vertexBuffers; - } + delete[] mHal.state.vertexBuffers; + delete[] mHal.state.primitives; + delete[] mHal.state.indexBuffers; - if (mHal.state.primitives) { - for (uint32_t i = 0; i < mHal.state.primitivesCount; i ++) { - mHal.state.primitives[i]->mIndexBuffer.clear(); - delete mHal.state.primitives[i]; - } - delete[] mHal.state.primitives; - } + delete[] mVertexBuffers; + delete[] mIndexBuffers; } void Mesh::init() { @@ -81,13 +92,11 @@ void Mesh::serialize(OStream *stream) const { stream->addU32(mHal.state.primitivesCount); // Store the primitives for (uint32_t pCount = 0; pCount < mHal.state.primitivesCount; pCount ++) { - Primitive_t * prim = mHal.state.primitives[pCount]; + stream->addU8((uint8_t)mHal.state.primitives[pCount]); - stream->addU8((uint8_t)prim->mPrimitive); - - if (prim->mIndexBuffer.get()) { + if (mHal.state.indexBuffers[pCount]) { stream->addU32(1); - prim->mIndexBuffer->serialize(stream); + mHal.state.indexBuffers[pCount]->serialize(stream); } else { stream->addU32(0); } @@ -173,10 +182,8 @@ void Mesh::renderPrimitive(Context *rsc, uint32_t primIndex) const { return; } - Primitive_t *prim = mHal.state.primitives[primIndex]; - - if (prim->mIndexBuffer.get()) { - renderPrimitiveRange(rsc, primIndex, 0, prim->mIndexBuffer->getType()->getDimX()); + if (mHal.state.indexBuffers[primIndex]) { + renderPrimitiveRange(rsc, primIndex, 0, mHal.state.indexBuffers[primIndex]->getType()->getDimX()); return; } @@ -194,14 +201,14 @@ void Mesh::renderPrimitiveRange(Context *rsc, uint32_t primIndex, uint32_t start void Mesh::uploadAll(Context *rsc) { for (uint32_t ct = 0; ct < mHal.state.vertexBuffersCount; ct ++) { - if (mHal.state.vertexBuffers[ct].get()) { - rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct].get()); + if (mHal.state.vertexBuffers[ct]) { + rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.vertexBuffers[ct]); } } for (uint32_t ct = 0; ct < mHal.state.primitivesCount; ct ++) { - if (mHal.state.primitives[ct]->mIndexBuffer.get()) { - rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.primitives[ct]->mIndexBuffer.get()); + if (mHal.state.indexBuffers[ct]) { + rsc->mHal.funcs.allocation.markDirty(rsc, mHal.state.indexBuffers[ct]); } } } @@ -290,7 +297,7 @@ void rsaMeshGetVertices(RsContext con, RsMesh mv, RsAllocation *vtxData, uint32_ rsAssert(vtxDataCount == sm->mHal.state.vertexBuffersCount); for (uint32_t ct = 0; ct < vtxDataCount; ct ++) { - vtxData[ct] = sm->mHal.state.vertexBuffers[ct].get(); + vtxData[ct] = sm->mHal.state.vertexBuffers[ct]; sm->mHal.state.vertexBuffers[ct]->incUserRef(); } } @@ -300,10 +307,10 @@ void rsaMeshGetIndices(RsContext con, RsMesh mv, RsAllocation *va, uint32_t *pri rsAssert(idxDataCount == sm->mHal.state.primitivesCount); for (uint32_t ct = 0; ct < idxDataCount; ct ++) { - va[ct] = sm->mHal.state.primitives[ct]->mIndexBuffer.get(); - primType[ct] = sm->mHal.state.primitives[ct]->mPrimitive; - if (sm->mHal.state.primitives[ct]->mIndexBuffer.get()) { - sm->mHal.state.primitives[ct]->mIndexBuffer->incUserRef(); + va[ct] = sm->mHal.state.indexBuffers[ct]; + primType[ct] = sm->mHal.state.primitives[ct]; + if (sm->mHal.state.indexBuffers[ct]) { + sm->mHal.state.indexBuffers[ct]->incUserRef(); } } } diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h index ed1e93d..0fc73fb 100644 --- a/libs/rs/rsMesh.h +++ b/libs/rs/rsMesh.h @@ -32,13 +32,6 @@ public: Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount); ~Mesh(); - // Either mIndexBuffer, mPrimitiveBuffer or both could have a NULL reference - // If both are null, mPrimitive only would be used to render the mesh - struct Primitive_t { - ObjectBaseRef<Allocation> mIndexBuffer; - RsPrimitive mPrimitive; - }; - virtual void serialize(OStream *stream) const; virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; } static Mesh *createFromStream(Context *rsc, IStream *stream); @@ -51,10 +44,13 @@ public: // Contains vertex data // Position, normal, texcoord, etc could either be strided in one allocation // of provided separetely in multiple ones - ObjectBaseRef<Allocation> *vertexBuffers; + Allocation **vertexBuffers; uint32_t vertexBuffersCount; - Primitive_t ** primitives; + // indexBuffers[i] could be NULL, in which case only primitives[i] is used + Allocation **indexBuffers; + uint32_t indexBuffersCount; + RsPrimitive *primitives; uint32_t primitivesCount; }; State state; @@ -62,12 +58,14 @@ public: Hal mHal; void setVertexBuffer(Allocation *vb, uint32_t index) { - mHal.state.vertexBuffers[index].set(vb); + mVertexBuffers[index].set(vb); + mHal.state.vertexBuffers[index] = vb; } void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) { - mHal.state.primitives[index]->mIndexBuffer.set(idx); - mHal.state.primitives[index]->mPrimitive = prim; + mIndexBuffers[index].set(idx); + mHal.state.indexBuffers[index] = idx; + mHal.state.primitives[index] = prim; } void render(Context *) const; @@ -80,6 +78,8 @@ public: float mBBoxMax[3]; void computeBBox(); protected: + ObjectBaseRef<Allocation> *mVertexBuffers; + ObjectBaseRef<Allocation> *mIndexBuffers; bool mInitialized; }; diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp index 4178aa5..a9fd877 100644 --- a/libs/rs/rsProgram.cpp +++ b/libs/rs/rsProgram.cpp @@ -37,22 +37,33 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, } } - mHal.state.textures = new ObjectBaseRef<Allocation>[mHal.state.texturesCount]; - mHal.state.samplers = new ObjectBaseRef<Sampler>[mHal.state.texturesCount]; + mTextures = new ObjectBaseRef<Allocation>[mHal.state.texturesCount]; + mSamplers = new ObjectBaseRef<Sampler>[mHal.state.texturesCount]; + mInputElements = new ObjectBaseRef<Element>[mHal.state.inputElementsCount]; + mConstantTypes = new ObjectBaseRef<Type>[mHal.state.constantsCount]; + mConstants = new ObjectBaseRef<Allocation>[mHal.state.constantsCount]; + + mHal.state.textures = new Allocation*[mHal.state.texturesCount]; + mHal.state.samplers = new Sampler*[mHal.state.texturesCount]; mHal.state.textureTargets = new RsTextureTarget[mHal.state.texturesCount]; - mHal.state.inputElements = new ObjectBaseRef<Element>[mHal.state.inputElementsCount]; - mHal.state.constantTypes = new ObjectBaseRef<Type>[mHal.state.constantsCount]; - mHal.state.constants = new ObjectBaseRef<Allocation>[mHal.state.constantsCount]; + mHal.state.inputElements = new Element*[mHal.state.inputElementsCount]; + mHal.state.constantTypes = new Type*[mHal.state.constantsCount]; + mHal.state.constants = new Allocation*[mHal.state.constantsCount]; + + // Will initialize everything + freeChildren(); uint32_t input = 0; uint32_t constant = 0; uint32_t texture = 0; for (uint32_t ct=0; ct < paramLength; ct+=2) { if (params[ct] == RS_PROGRAM_PARAM_INPUT) { - mHal.state.inputElements[input++].set(reinterpret_cast<Element *>(params[ct+1])); + mInputElements[input].set(reinterpret_cast<Element *>(params[ct+1])); + mHal.state.inputElements[input++] = reinterpret_cast<Element *>(params[ct+1]); } if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) { - mHal.state.constantTypes[constant++].set(reinterpret_cast<Type *>(params[ct+1])); + mConstantTypes[constant].set(reinterpret_cast<Type *>(params[ct+1])); + mHal.state.constantTypes[constant++] = reinterpret_cast<Type *>(params[ct+1]); } if (params[ct] == RS_PROGRAM_PARAM_TEXTURE_TYPE) { mHal.state.textureTargets[texture++] = (RsTextureTarget)params[ct+1]; @@ -72,6 +83,12 @@ Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength, Program::~Program() { freeChildren(); + delete[] mTextures; + delete[] mSamplers; + delete[] mInputElements; + delete[] mConstantTypes; + delete[] mConstants; + delete[] mHal.state.textures; delete[] mHal.state.samplers; delete[] mHal.state.textureTargets; @@ -110,6 +127,12 @@ void Program::initMemberVars() { mHal.state.constantsCount = 0; mHal.state.texturesCount = 0; + mTextures = NULL; + mSamplers = NULL; + mInputElements = NULL; + mConstantTypes = NULL; + mConstants = NULL; + mIsInternal = false; } @@ -121,20 +144,21 @@ void Program::bindAllocation(Context *rsc, Allocation *alloc, uint32_t slot) { rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind allocation"); return; } - if (alloc->getType() != mHal.state.constantTypes[slot].get()) { + if (alloc->getType() != mConstantTypes[slot].get()) { LOGE("Attempt to bind alloc at slot %u, on shader id %u, but types mismatch", slot, (uint32_t)this); rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind allocation"); return; } } - if (mHal.state.constants[slot].get() == alloc) { + if (mConstants[slot].get() == alloc) { return; } - if (mHal.state.constants[slot].get()) { - mHal.state.constants[slot].get()->removeProgramToDirty(this); + if (mConstants[slot].get()) { + mConstants[slot]->removeProgramToDirty(this); } - mHal.state.constants[slot].set(alloc); + mConstants[slot].set(alloc); + mHal.state.constants[slot] = alloc; if (alloc) { alloc->addProgramToDirty(this); } @@ -154,7 +178,9 @@ void Program::bindTexture(Context *rsc, uint32_t slot, Allocation *a) { return; } - mHal.state.textures[slot].set(a); + mTextures[slot].set(a); + mHal.state.textures[slot] = a; + mDirty = true; } @@ -165,7 +191,8 @@ void Program::bindSampler(Context *rsc, uint32_t slot, Sampler *s) { return; } - mHal.state.samplers[slot].set(s); + mSamplers[slot].set(s); + mHal.state.samplers[slot] = s; mDirty = true; } diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h index 3237a72..06fc3ec 100644 --- a/libs/rs/rsProgram.h +++ b/libs/rs/rsProgram.h @@ -30,19 +30,6 @@ namespace renderscript { class Program : public ProgramBase { 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); - - bool isUserProgram() const {return !mIsInternal;} - - void bindTexture(Context *, uint32_t slot, Allocation *); - void bindSampler(Context *, uint32_t slot, Sampler *); - struct Hal { mutable void *drv; @@ -53,25 +40,43 @@ public: // and filtered. // // Constants are strictly accessed by the shader code - ObjectBaseRef<Allocation> *textures; + Allocation **textures; RsTextureTarget *textureTargets; uint32_t texturesCount; - ObjectBaseRef<Sampler> *samplers; + Sampler **samplers; uint32_t samplersCount; - ObjectBaseRef<Allocation> *constants; - ObjectBaseRef<Type> *constantTypes; + Allocation **constants; + Type **constantTypes; uint32_t constantsCount; - ObjectBaseRef<Element> *inputElements; + Element **inputElements; uint32_t inputElementsCount; }; State state; }; Hal mHal; + 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); + + bool isUserProgram() const {return !mIsInternal;} + + void bindTexture(Context *, uint32_t slot, Allocation *); + void bindSampler(Context *, uint32_t slot, Sampler *); + protected: + ObjectBaseRef<Allocation> *mTextures; + ObjectBaseRef<Sampler> *mSamplers; + ObjectBaseRef<Allocation> *mConstants; + ObjectBaseRef<Type> *mConstantTypes; + ObjectBaseRef<Element> *mInputElements; + bool mIsInternal; String8 mUserShader; void initMemberVars(); diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index ff29520..81eedc4 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -42,7 +42,7 @@ void ProgramFragment::setConstantColor(Context *rsc, float r, float g, float b, rsc->setError(RS_ERROR_BAD_SHADER, "Cannot set fixed function emulation color on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { LOGE("Unable to set fixed function emulation color because allocation is missing"); rsc->setError(RS_ERROR_BAD_SHADER, "Unable to set fixed function emulation color because allocation is missing"); return; @@ -62,7 +62,7 @@ void ProgramFragment::setup(Context *rsc, ProgramFragmentState *state) { state->mLast.set(this); for (uint32_t ct=0; ct < mHal.state.texturesCount; ct++) { - if (!mHal.state.textures[ct].get()) { + if (!mHal.state.textures[ct]) { LOGE("No texture bound for shader id %u, texture unit %u", (uint)this, ct); rsc->setError(RS_ERROR_BAD_SHADER, "No texture bound"); continue; diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h index 20af30a..c552ea3 100644 --- a/libs/rs/rsProgramRaster.h +++ b/libs/rs/rsProgramRaster.h @@ -24,17 +24,16 @@ namespace android { namespace renderscript { class ProgramRasterState; - +/***************************************************************************** + * 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 ProgramRaster : public ProgramBase { public: - virtual void setup(const Context *, ProgramRasterState *); - virtual void serialize(OStream *stream) const; - virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; } - static ProgramRaster *createFromStream(Context *rsc, IStream *stream); - - static ObjectBaseRef<ProgramRaster> getProgramRaster(Context *rsc, - bool pointSprite, - RsCullMode cull); struct Hal { mutable void *drv; @@ -46,6 +45,14 @@ public: }; Hal mHal; + virtual void setup(const Context *, ProgramRasterState *); + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; } + static ProgramRaster *createFromStream(Context *rsc, IStream *stream); + + static ObjectBaseRef<ProgramRaster> getProgramRaster(Context *rsc, + bool pointSprite, + RsCullMode cull); protected: virtual void preDestroy() const; virtual ~ProgramRaster(); diff --git a/libs/rs/rsProgramStore.h b/libs/rs/rsProgramStore.h index e21f039..9bb2795 100644 --- a/libs/rs/rsProgramStore.h +++ b/libs/rs/rsProgramStore.h @@ -25,23 +25,16 @@ namespace android { namespace renderscript { class ProgramStoreState; - +/***************************************************************************** + * 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 ProgramStore : public ProgramBase { public: - virtual void setup(const Context *, ProgramStoreState *); - - virtual void serialize(OStream *stream) const; - virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; } - static ProgramStore *createFromStream(Context *rsc, IStream *stream); - static ObjectBaseRef<ProgramStore> getProgramStore(Context *, - bool colorMaskR, bool colorMaskG, - bool colorMaskB, bool colorMaskA, - bool depthMask, bool ditherEnable, - RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, - RsDepthFunc depthFunc); - - void init(); - struct Hal { mutable void *drv; @@ -64,6 +57,18 @@ public: }; Hal mHal; + virtual void setup(const Context *, ProgramStoreState *); + + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; } + static ProgramStore *createFromStream(Context *rsc, IStream *stream); + static ObjectBaseRef<ProgramStore> getProgramStore(Context *, + bool colorMaskR, bool colorMaskG, + bool colorMaskB, bool colorMaskA, + bool depthMask, bool ditherEnable, + RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc, + RsDepthFunc depthFunc); + void init(); protected: virtual void preDestroy() const; virtual ~ProgramStore(); diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp index 51cb2a8a..4a13622 100644 --- a/libs/rs/rsProgramVertex.cpp +++ b/libs/rs/rsProgramVertex.cpp @@ -38,7 +38,7 @@ void ProgramVertex::setup(Context *rsc, ProgramVertexState *state) { } if (!isUserProgram()) { - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrices because allocation is missing"); return; @@ -65,7 +65,7 @@ void ProgramVertex::setProjectionMatrix(Context *rsc, const rsc_Matrix *m) const "Attempting to set fixed function emulation matrix projection on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrix projection because allocation is missing"); return; @@ -81,7 +81,7 @@ void ProgramVertex::setModelviewMatrix(Context *rsc, const rsc_Matrix *m) const "Attempting to set fixed function emulation matrix modelview on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrix modelview because allocation is missing"); return; @@ -97,7 +97,7 @@ void ProgramVertex::setTextureMatrix(Context *rsc, const rsc_Matrix *m) const { "Attempting to set fixed function emulation matrix texture on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to set fixed function emulation matrix texture because allocation is missing"); return; @@ -113,7 +113,7 @@ void ProgramVertex::getProjectionMatrix(Context *rsc, rsc_Matrix *m) const { "Attempting to get fixed function emulation matrix projection on user program"); return; } - if (mHal.state.constants[0].get() == NULL) { + if (mHal.state.constants[0] == NULL) { rsc->setError(RS_ERROR_FATAL_UNKNOWN, "Unable to get fixed function emulation matrix projection because allocation is missing"); return; diff --git a/libs/rs/rsSampler.h b/libs/rs/rsSampler.h index e698132..654cd9c 100644 --- a/libs/rs/rsSampler.h +++ b/libs/rs/rsSampler.h @@ -27,23 +27,16 @@ namespace renderscript { const static uint32_t RS_MAX_SAMPLER_SLOT = 16; class SamplerState; - +/***************************************************************************** + * 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 Sampler : public ObjectBase { public: - static ObjectBaseRef<Sampler> getSampler(Context *, - RsSamplerValue magFilter, - RsSamplerValue minFilter, - RsSamplerValue wrapS, - RsSamplerValue wrapT, - RsSamplerValue wrapR, - float aniso = 1.0f); - void bindToContext(SamplerState *, uint32_t slot); - void unbindFromContext(SamplerState *); - - virtual void serialize(OStream *stream) const; - virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } - static Sampler *createFromStream(Context *rsc, IStream *stream); - struct Hal { mutable void *drv; @@ -59,6 +52,20 @@ public: }; Hal mHal; + static ObjectBaseRef<Sampler> getSampler(Context *, + RsSamplerValue magFilter, + RsSamplerValue minFilter, + RsSamplerValue wrapS, + RsSamplerValue wrapT, + RsSamplerValue wrapR, + float aniso = 1.0f); + void bindToContext(SamplerState *, uint32_t slot); + void unbindFromContext(SamplerState *); + + virtual void serialize(OStream *stream) const; + virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } + static Sampler *createFromStream(Context *rsc, IStream *stream); + protected: int32_t mBoundSlot; diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp index 2e7f213..cd7b3a7 100644 --- a/libs/rs/rsScriptC.cpp +++ b/libs/rs/rsScriptC.cpp @@ -21,6 +21,7 @@ #ifndef ANDROID_RS_SERIALIZE #include <bcinfo/BitcodeTranslator.h> +#include <bcinfo/BitcodeWrapper.h> #endif using namespace android; @@ -196,7 +197,24 @@ bool ScriptC::runCompiler(Context *rsc, //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen); #ifndef ANDROID_RS_SERIALIZE - uint32_t sdkVersion = rsc->getTargetSdkVersion(); + uint32_t sdkVersion = 0; + bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen); + if (!bcWrapper.unwrap()) { + LOGE("Bitcode is not in proper container format (raw or wrapper)"); + return false; + } + + rsAssert(bcWrapper.getHeaderVersion() == 0); + if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) { + sdkVersion = bcWrapper.getTargetAPI(); + } + + if (sdkVersion == 0) { + // This signals that we didn't have a wrapper containing information + // about the bitcode. + sdkVersion = rsc->getTargetSdkVersion(); + } + if (BT) { delete BT; } diff --git a/libs/rs/scriptc/rs_allocation.rsh b/libs/rs/scriptc/rs_allocation.rsh index 154a099..9ec03bf 100644 --- a/libs/rs/scriptc/rs_allocation.rsh +++ b/libs/rs/scriptc/rs_allocation.rsh @@ -14,6 +14,31 @@ * limitations under the License. */ +/*! \mainpage notitle + * + * Renderscript is a high-performance runtime that provides graphics rendering and + * compute operations at the native level. Renderscript code is compiled on devices + * at runtime to allow platform-independence as well. + * This reference documentation describes the Renderscript runtime APIs, which you + * can utilize to write Renderscript code in C99. The Renderscript header + * files are automatically included for you, except for the rs_graphics.rsh header. If + * you are doing graphics rendering, include the graphics header file like this: + * + * <code>#include "rs_graphics.rsh"</code> + * + * To use Renderscript, you need to utilize the Renderscript runtime APIs documented here + * as well as the Android framework APIs for Renderscript. + * For documentation on the Android framework APIs, see the <a target="_parent" href= + * "http://developer.android.com/reference/android/renderscript/package-summary.html"> + * android.renderscript</a> package reference. + * For more information on how to develop with Renderscript and how the runtime and + * Android framework APIs interact, see the <a target="_parent" href= + * "http://developer.android.com/guide/topics/renderscript/index.html">Renderscript + * developer guide</a> and the <a target="_parent" href= + * "http://developer.android.com/resources/samples/RenderScript/index.html"> + * Renderscript samples</a>. + */ + /** @file rs_allocation.rsh * \brief Allocation routines * diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh index 3e9339e..2581953 100644 --- a/libs/rs/scriptc/rs_graphics.rsh +++ b/libs/rs/scriptc/rs_graphics.rsh @@ -22,7 +22,6 @@ */ #ifndef __RS_GRAPHICS_RSH__ #define __RS_GRAPHICS_RSH__ - #if (defined(RS_VERSION) && (RS_VERSION >= 14)) /** * Set the color target used for all subsequent rendering calls diff --git a/libs/rs/scriptc/rs_quaternion.rsh b/libs/rs/scriptc/rs_quaternion.rsh index 23945ae..4e08d2f 100644 --- a/libs/rs/scriptc/rs_quaternion.rsh +++ b/libs/rs/scriptc/rs_quaternion.rsh @@ -66,19 +66,6 @@ rsQuaternionMultiply(rs_quaternion *q, float s) { } /** - * Multiply quaternion by another quaternion - * @param q destination quaternion - * @param rhs right hand side quaternion to multiply by - */ -static void __attribute__((overloadable)) -rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) { - q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w; - q->x = q->x*rhs->w + q->y*rhs->z - q->z*rhs->y + q->w*rhs->x; - q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->x + q->w*rhs->y; - q->z = q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z; -} - -/** * Add two quaternions * @param q destination quaternion to add to * @param rsh right hand side quaternion to add @@ -168,6 +155,23 @@ rsQuaternionNormalize(rs_quaternion *q) { } /** + * Multiply quaternion by another quaternion + * @param q destination quaternion + * @param rhs right hand side quaternion to multiply by + */ +static void __attribute__((overloadable)) +rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) { + rs_quaternion qtmp; + rsQuaternionSet(&qtmp, q); + + q->w = qtmp.w*rhs->w - qtmp.x*rhs->x - qtmp.y*rhs->y - qtmp.z*rhs->z; + q->x = qtmp.w*rhs->x + qtmp.x*rhs->w + qtmp.y*rhs->z - qtmp.z*rhs->y; + q->y = qtmp.w*rhs->y + qtmp.y*rhs->w + qtmp.z*rhs->x - qtmp.x*rhs->z; + q->z = qtmp.w*rhs->z + qtmp.z*rhs->w + qtmp.x*rhs->y - qtmp.y*rhs->x; + rsQuaternionNormalize(q); +} + +/** * Performs spherical linear interpolation between two quaternions * @param q result quaternion from interpolation * @param q0 first param @@ -222,34 +226,26 @@ rsQuaternionSlerp(rs_quaternion *q, const rs_quaternion *q0, const rs_quaternion * @param p normalized quaternion */ static void rsQuaternionGetMatrixUnit(rs_matrix4x4 *m, const rs_quaternion *q) { - float x2 = 2.0f * q->x * q->x; - float y2 = 2.0f * q->y * q->y; - float z2 = 2.0f * q->z * q->z; - float xy = 2.0f * q->x * q->y; - float wz = 2.0f * q->w * q->z; - float xz = 2.0f * q->x * q->z; - float wy = 2.0f * q->w * q->y; - float wx = 2.0f * q->w * q->x; - float yz = 2.0f * q->y * q->z; - - m->m[0] = 1.0f - y2 - z2; - m->m[1] = xy - wz; - m->m[2] = xz + wy; - m->m[3] = 0.0f; - - m->m[4] = xy + wz; - m->m[5] = 1.0f - x2 - z2; - m->m[6] = yz - wx; - m->m[7] = 0.0f; - - m->m[8] = xz - wy; - m->m[9] = yz - wx; - m->m[10] = 1.0f - x2 - y2; - m->m[11] = 0.0f; - - m->m[12] = 0.0f; - m->m[13] = 0.0f; - m->m[14] = 0.0f; + float xx = q->x * q->x; + float xy = q->x * q->y; + float xz = q->x * q->z; + float xw = q->x * q->w; + float yy = q->y * q->y; + float yz = q->y * q->z; + float yw = q->y * q->w; + float zz = q->z * q->z; + float zw = q->z * q->w; + + m->m[0] = 1.0f - 2.0f * ( yy + zz ); + m->m[4] = 2.0f * ( xy - zw ); + m->m[8] = 2.0f * ( xz + yw ); + m->m[1] = 2.0f * ( xy + zw ); + m->m[5] = 1.0f - 2.0f * ( xx + zz ); + m->m[9] = 2.0f * ( yz - xw ); + m->m[2] = 2.0f * ( xz - yw ); + m->m[6] = 2.0f * ( yz + xw ); + m->m[10] = 1.0f - 2.0f * ( xx + yy ); + m->m[3] = m->m[7] = m->m[11] = m->m[12] = m->m[13] = m->m[14] = 0.0f; m->m[15] = 1.0f; } |