summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2010-10-26 13:09:17 -0700
committerJason Sams <rjsams@android.com>2010-10-26 13:09:17 -0700
commitf0c1df480304a72ce41e7d4b088319cbd7f0938a (patch)
tree3e49b31c4490d4b8d7e0ff7893ef0e4e9c7063ee
parent1f9ba735cc429ae8df140644f6f0a4481f2a8068 (diff)
downloadrs-f0c1df480304a72ce41e7d4b088319cbd7f0938a.tar.gz
Begin adding async allocation creation.
Change-Id: I5d1381699e2b334c1d824f357bd6b310a5f79be8 Implement async bitmap upload and clean up types. Change-Id: Icbe9894e04c1319351c1cd75b0e0017855198f20
-rw-r--r--RenderScript.h2
-rw-r--r--rs.spec22
-rw-r--r--rsAllocation.cpp100
-rw-r--r--rsElement.cpp1
-rw-r--r--rsFont.cpp23
-rw-r--r--rsObjectBase.cpp9
-rw-r--r--rsObjectBase.h4
-rw-r--r--rsProgramFragment.cpp5
-rw-r--r--rsProgramVertex.cpp5
-rw-r--r--rsType.cpp117
-rw-r--r--rsType.h19
11 files changed, 113 insertions, 194 deletions
diff --git a/RenderScript.h b/RenderScript.h
index d078d469..1d67329e 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -290,6 +290,8 @@ typedef struct {
// Async commands for returning new IDS
RsType rsaTypeCreate(RsContext, RsElement, uint32_t dimCount,
const RsDimension *dims, const uint32_t *vals);
+RsAllocation rsaAllocationCreateTyped(RsContext rsc, RsType vtype);
+RsAllocation rsaAllocationCreateFromBitmap(RsContext con, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data);
#ifndef NO_RS_FUNCS
diff --git a/rs.spec b/rs.spec
index eb2942e7..3e131b27 100644
--- a/rs.spec
+++ b/rs.spec
@@ -104,17 +104,6 @@ TypeGetNativeData {
param uint32_t typeDataSize
}
-AllocationCreateTyped {
- param RsType type
- ret RsAllocation
- }
-
-AllocationCreateSized {
- param RsElement e
- param size_t count
- ret RsAllocation
- }
-
AllocationUpdateFromBitmap {
param RsAllocation alloc
param RsElement srcFmt
@@ -129,17 +118,6 @@ AllocationCreateBitmapRef {
ret RsAllocation
}
-AllocationCreateFromBitmap {
- param uint32_t width
- param uint32_t height
- param RsElement dstFmt
- param RsElement srcFmt
- param bool genMips
- param const void * data
- ret RsAllocation
- }
-
-
AllocationUploadToTexture {
param RsAllocation alloc
param bool genMipMaps
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index fc41a722..b4872e3d 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -563,24 +563,6 @@ void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY)
namespace android {
namespace renderscript {
-RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype)
-{
- const Type * type = static_cast<const Type *>(vtype);
-
- Allocation * alloc = new Allocation(rsc, type);
- alloc->incUserRef();
- return alloc;
-}
-
-RsAllocation rsi_AllocationCreateSized(Context *rsc, RsElement e, size_t count)
-{
- Type * type = new Type(rsc);
- type->setDimX(count);
- type->setElement(static_cast<Element *>(e));
- type->compute();
- return rsi_AllocationCreateTyped(rsc, type);
-}
-
void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel)
{
Allocation *alloc = static_cast<Allocation *>(va);
@@ -786,42 +768,6 @@ void rsi_AllocationUpdateFromBitmap(Context *rsc, RsAllocation va, RsElement _sr
}
}
-RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data)
-{
- const Element *src = static_cast<const Element *>(_src);
- const Element *dst = static_cast<const Element *>(_dst);
-
- //LOGE("%p rsi_AllocationCreateFromBitmap %i %i %i", rsc, w, h, genMips);
- RsDimension dims[] = {RS_DIMENSION_X, RS_DIMENSION_Y, RS_DIMENSION_LOD};
- uint32_t dimValues[] = {w, h, genMips};
- RsType type = rsaTypeCreate(rsc, _dst, 3, dims, dimValues);
-
- RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, type);
- Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
- if (texAlloc == NULL) {
- LOGE("Memory allocation failure");
- return NULL;
- }
-
- ElementConverter_t cvt = pickConverter(dst, src);
- if (cvt) {
- cvt(texAlloc->getPtr(), data, w * h);
- if (genMips) {
- Adapter2D adapt(rsc, texAlloc);
- Adapter2D adapt2(rsc, texAlloc);
- for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
- adapt.setLOD(lod);
- adapt2.setLOD(lod + 1);
- mip(adapt2, adapt);
- }
- }
- } else {
- rsc->setError(RS_ERROR_BAD_VALUE, "Unsupported bitmap format");
- }
-
- return texAlloc;
-}
-
void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
@@ -882,3 +828,49 @@ const void* rsi_AllocationGetType(Context *rsc, RsAllocation va)
}
}
+
+RsAllocation rsaAllocationCreateTyped(RsContext con, RsType vtype)
+{
+ Context *rsc = static_cast<Context *>(con);
+ Allocation * alloc = new Allocation(rsc, static_cast<Type *>(vtype));
+ alloc->incUserRef();
+ return alloc;
+}
+
+RsAllocation rsaAllocationCreateFromBitmap(RsContext con, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data)
+{
+ Context *rsc = static_cast<Context *>(con);
+ const Element *src = static_cast<const Element *>(_src);
+ const Element *dst = static_cast<const Element *>(_dst);
+
+ //LOGE("%p rsi_AllocationCreateFromBitmap %i %i %i", rsc, w, h, genMips);
+ RsDimension dims[] = {RS_DIMENSION_X, RS_DIMENSION_Y, RS_DIMENSION_LOD};
+ uint32_t dimValues[] = {w, h, genMips};
+ RsType type = rsaTypeCreate(rsc, _dst, 3, dims, dimValues);
+
+ RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, type);
+ Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
+ if (texAlloc == NULL) {
+ LOGE("Memory allocation failure");
+ return NULL;
+ }
+
+ ElementConverter_t cvt = pickConverter(dst, src);
+ if (cvt) {
+ cvt(texAlloc->getPtr(), data, w * h);
+ if (genMips) {
+ Adapter2D adapt(rsc, texAlloc);
+ Adapter2D adapt2(rsc, texAlloc);
+ for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
+ adapt.setLOD(lod);
+ adapt2.setLOD(lod + 1);
+ mip(adapt2, adapt);
+ }
+ }
+ } else {
+ rsc->setError(RS_ERROR_BAD_VALUE, "Unsupported bitmap format");
+ }
+
+ return texAlloc;
+}
+
diff --git a/rsElement.cpp b/rsElement.cpp
index dc021fcb..096115cd 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -399,6 +399,7 @@ void rsi_ElementGetSubElements(Context *rsc, RsElement elem, uint32_t *ids, cons
rsAssert(e->getFieldCount() == dataSize);
for(uint32_t i = 0; i < dataSize; i ++) {
+ e->getField(i)->incUserRef();
ids[i] = (uint32_t)e->getField(i);
names[i] = e->getFieldName(i);
}
diff --git a/rsFont.cpp b/rsFont.cpp
index d171a481..9e762152 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -511,10 +511,7 @@ void FontState::initRenderState()
mRSC->mStateElement.elementBuilderAdd(gammaElem, "Gamma", 1);
const Element *constInput = mRSC->mStateElement.elementBuilderCreate(mRSC);
- Type *inputType = new Type(mRSC);
- inputType->setElement(constInput);
- inputType->setDimX(1);
- inputType->compute();
+ Type *inputType = Type::getType(mRSC, constInput, 1, 0, 0, false, false);
uint32_t tmp[4];
tmp[0] = RS_PROGRAM_PARAM_CONSTANT;
@@ -546,11 +543,7 @@ void FontState::initTextTexture()
const Element *alphaElem = Element::create(mRSC, RS_TYPE_UNSIGNED_8, RS_KIND_PIXEL_A, true, 1);
// We will allocate a texture to initially hold 32 character bitmaps
- Type *texType = new Type(mRSC);
- texType->setElement(alphaElem);
- texType->setDimX(1024);
- texType->setDimY(256);
- texType->compute();
+ Type *texType = Type::getType(mRSC, alphaElem, 1024, 256, 0, false, false);
Allocation *cacheAlloc = new Allocation(mRSC, texType);
mTextTexture.set(cacheAlloc);
@@ -578,11 +571,8 @@ void FontState::initVertexArrayBuffers()
{
// Now lets write index data
const Element *indexElem = Element::create(mRSC, RS_TYPE_UNSIGNED_16, RS_KIND_USER, false, 1);
- Type *indexType = new Type(mRSC);
uint32_t numIndicies = mMaxNumberOfQuads * 6;
- indexType->setDimX(numIndicies);
- indexType->setElement(indexElem);
- indexType->compute();
+ Type *indexType = Type::getType(mRSC, indexElem, numIndicies, 0, 0, false, false);
Allocation *indexAlloc = new Allocation(mRSC, indexType);
uint16_t *indexPtr = (uint16_t*)indexAlloc->getPtr();
@@ -612,10 +602,9 @@ void FontState::initVertexArrayBuffers()
mRSC->mStateElement.elementBuilderAdd(texElem, "texture0", 1);
const Element *vertexDataElem = mRSC->mStateElement.elementBuilderCreate(mRSC);
- Type *vertexDataType = new Type(mRSC);
- vertexDataType->setDimX(mMaxNumberOfQuads * 4);
- vertexDataType->setElement(vertexDataElem);
- vertexDataType->compute();
+ Type *vertexDataType = Type::getType(mRSC, vertexDataElem,
+ mMaxNumberOfQuads * 4,
+ 0, 0, false, false);
Allocation *vertexAlloc = new Allocation(mRSC, vertexDataType);
mTextMeshPtr = (float*)vertexAlloc->getPtr();
diff --git a/rsObjectBase.cpp b/rsObjectBase.cpp
index 724172ee..44dc0425 100644
--- a/rsObjectBase.cpp
+++ b/rsObjectBase.cpp
@@ -120,8 +120,15 @@ bool ObjectBase::checkDelete(const ObjectBase *ref)
bool ObjectBase::decUserRef() const
{
- //LOGV("ObjectBase %p decU ref %i, %i", this, mUserRefCount, mSysRefCount);
rsAssert(mUserRefCount > 0);
+#if RS_OBJECT_DEBUG
+ LOGV("ObjectBase %p decU ref %i, %i", this, mUserRefCount, mSysRefCount);
+ if (mUserRefCount <= 0) {
+ mStack.dump();
+ }
+#endif
+
+
if ((android_atomic_dec(&mUserRefCount) <= 1) &&
(android_atomic_acquire_load(&mSysRefCount) <= 0)) {
return checkDelete(this);
diff --git a/rsObjectBase.h b/rsObjectBase.h
index 5f03db5d..5cc275a2 100644
--- a/rsObjectBase.h
+++ b/rsObjectBase.h
@@ -21,9 +21,7 @@
#define RS_OBJECT_DEBUG 0
-#if RS_OBJECT_DEBUG
- #include <utils/CallStack.h>
-#endif
+#include <utils/CallStack.h>
namespace android {
namespace renderscript {
diff --git a/rsProgramFragment.cpp b/rsProgramFragment.cpp
index 33399d53..800854b4 100644
--- a/rsProgramFragment.cpp
+++ b/rsProgramFragment.cpp
@@ -198,10 +198,7 @@ void ProgramFragmentState::init(Context *rsc)
rsc->mStateElement.elementBuilderAdd(colorElem, "Color", 1);
const Element *constInput = rsc->mStateElement.elementBuilderCreate(rsc);
- Type *inputType = new Type(rsc);
- inputType->setElement(constInput);
- inputType->setDimX(1);
- inputType->compute();
+ Type *inputType = Type::getType(rsc, constInput, 1, 0, 0, false, false);
uint32_t tmp[4];
tmp[0] = RS_PROGRAM_PARAM_CONSTANT;
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index d12439f8..4e64008c 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -257,10 +257,7 @@ void ProgramVertexState::init(Context *rsc)
rsc->mStateElement.elementBuilderAdd(f2Elem, "texture0", 1);
const Element *attrElem = rsc->mStateElement.elementBuilderCreate(rsc);
- Type *inputType = new Type(rsc);
- inputType->setElement(constInput);
- inputType->setDimX(1);
- inputType->compute();
+ Type *inputType = Type::getType(rsc, constInput, 1, 0, 0, false, false);
String8 shaderString(RS_SHADER_INTERNAL);
shaderString.append("varying vec4 varColor;\n");
diff --git a/rsType.cpp b/rsType.cpp
index 82ad33e4..7ef24642 100644
--- a/rsType.cpp
+++ b/rsType.cpp
@@ -276,20 +276,12 @@ Type *Type::createFromStream(Context *rsc, IStream *stream)
return NULL;
}
- Type *type = new Type(rsc);
- type->mDimX = stream->loadU32();
- type->mDimY = stream->loadU32();
- type->mDimZ = stream->loadU32();
-
- uint8_t temp = stream->loadU8();
- type->mDimLOD = temp != 0;
-
- temp = stream->loadU8();
- type->mFaces = temp != 0;
-
- type->setElement(elem);
-
- return type;
+ uint32_t x = stream->loadU32();
+ uint32_t y = stream->loadU32();
+ uint32_t z = stream->loadU32();
+ uint8_t lod = stream->loadU8();
+ uint8_t faces = stream->loadU8();
+ return Type::getType(rsc, elem, x, y, z, lod != 0, faces !=0 );
}
bool Type::getIsNp2() const
@@ -325,56 +317,55 @@ bool Type::isEqual(const Type *other) const {
return false;
}
-Type * Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const
+Type * Type::getType(Context *rsc, const Element *e,
+ uint32_t dimX, uint32_t dimY, uint32_t dimZ,
+ bool dimLOD, bool dimFaces)
{
TypeState * stc = &rsc->mStateType;
+
+ ObjectBase::asyncLock();
for (uint32_t ct=0; ct < stc->mTypes.size(); ct++) {
Type *t = stc->mTypes[ct];
- if (t->getElement() != mElement.get()) continue;
+ if (t->getElement() != e) continue;
if (t->getDimX() != dimX) continue;
- if (t->getDimY() != mDimY) continue;
- if (t->getDimZ() != mDimZ) continue;
- if (t->getDimLOD() != mDimLOD) continue;
- if (t->getDimFaces() != mFaces) continue;
+ if (t->getDimY() != dimY) continue;
+ if (t->getDimZ() != dimZ) continue;
+ if (t->getDimLOD() != dimLOD) continue;
+ if (t->getDimFaces() != dimFaces) continue;
t->incUserRef();
+ ObjectBase::asyncUnlock();
return t;
}
+ ObjectBase::asyncUnlock();
+
Type *nt = new Type(rsc);
- nt->mElement.set(mElement);
+ nt->mElement.set(e);
nt->mDimX = dimX;
- nt->mDimY = mDimY;
- nt->mDimZ = mDimZ;
- nt->mDimLOD = mDimLOD;
- nt->mFaces = mFaces;
+ nt->mDimY = dimY;
+ nt->mDimZ = dimZ;
+ nt->mDimLOD = dimLOD;
+ nt->mFaces = dimFaces;
nt->compute();
+ nt->incUserRef();
+
+ ObjectBase::asyncLock();
+ stc->mTypes.push(nt);
+ ObjectBase::asyncUnlock();
+
return nt;
}
-Type * Type::cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const
+Type * Type::cloneAndResize1D(Context *rsc, uint32_t dimX) const
{
- TypeState * stc = &rsc->mStateType;
- for (uint32_t ct=0; ct < stc->mTypes.size(); ct++) {
- Type *t = stc->mTypes[ct];
- if (t->getElement() != mElement.get()) continue;
- if (t->getDimX() != dimX) continue;
- if (t->getDimY() != dimY) continue;
- if (t->getDimZ() != mDimZ) continue;
- if (t->getDimLOD() != mDimLOD) continue;
- if (t->getDimFaces() != mFaces) continue;
- t->incUserRef();
- return t;
- }
+ return getType(rsc, mElement.get(), dimX,
+ mDimY, mDimZ, mDimLOD, mFaces);
+}
- Type *nt = new Type(rsc);
- nt->mElement.set(mElement);
- nt->mDimX = dimX;
- nt->mDimY = dimY;
- nt->mDimZ = mDimZ;
- nt->mDimLOD = mDimLOD;
- nt->mFaces = mFaces;
- nt->compute();
- return nt;
+Type * Type::cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const
+{
+ return getType(rsc, mElement.get(), dimX, dimY,
+ mDimZ, mDimLOD, mFaces);
}
@@ -396,7 +387,7 @@ void rsi_TypeGetNativeData(Context *rsc, RsType type, uint32_t *typeData, uint32
(*typeData++) = t->getDimLOD();
(*typeData++) = t->getDimFaces() ? 1 : 0;
(*typeData++) = (uint32_t)t->getElement();
-
+ t->getElement()->incUserRef();
}
@@ -430,34 +421,6 @@ RsType rsaTypeCreate(RsContext con, RsElement _e, uint32_t dimCount,
}
}
- ObjectBase::asyncLock();
- for (uint32_t ct=0; ct < stc->mTypes.size(); ct++) {
- Type *t = stc->mTypes[ct];
- if (t->getElement() != e) continue;
- if (t->getDimX() != dimX) continue;
- if (t->getDimY() != dimY) continue;
- if (t->getDimZ() != dimZ) continue;
- if (t->getDimLOD() != dimLOD) continue;
- if (t->getDimFaces() != dimFaces) continue;
- t->incUserRef();
- ObjectBase::asyncUnlock();
- return t;
- }
- ObjectBase::asyncUnlock();
-
- Type * st = new Type(rsc);
- st->incUserRef();
- st->setDimX(dimX);
- st->setDimY(dimY);
- st->setDimZ(dimZ);
- st->setElement(e);
- st->setDimLOD(dimLOD);
- st->setDimFaces(dimFaces);
- st->compute();
-
- ObjectBase::asyncLock();
- stc->mTypes.push(st);
- ObjectBase::asyncUnlock();
- return st;
+ return Type::getType(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
}
diff --git a/rsType.h b/rsType.h
index 6b894138..0ca5bb6e 100644
--- a/rsType.h
+++ b/rsType.h
@@ -28,9 +28,6 @@ namespace renderscript {
class Type : public ObjectBase
{
public:
- Type(Context *);
- virtual ~Type();
-
Type * createTex2D(const Element *, size_t w, size_t h, bool mip);
@@ -58,15 +55,6 @@ public:
uint32_t getLODCount() const {return mLODCount;}
bool getIsNp2() const;
-
- void setElement(const Element *e) {mElement.set(e);}
- void setDimX(uint32_t v) {mDimX = v;}
- void setDimY(uint32_t v) {mDimY = v;}
- void setDimZ(uint32_t v) {mDimZ = v;}
- void setDimFaces(bool v) {mFaces = v;}
- void setDimLOD(bool v) {mDimLOD = v;}
-
-
void clear();
void compute();
@@ -82,6 +70,10 @@ public:
Type * cloneAndResize1D(Context *rsc, uint32_t dimX) const;
Type * cloneAndResize2D(Context *rsc, uint32_t dimX, uint32_t dimY) const;
+ static Type * getType(Context *rsc, const Element *e,
+ uint32_t dimX, uint32_t dimY, uint32_t dimZ,
+ bool dimLOD, bool dimFaces);
+
protected:
struct LOD {
size_t mX;
@@ -124,10 +116,13 @@ protected:
bool isValidGLComponent(uint32_t fieldIdx);
void makeGLComponents();
+
protected:
virtual void preDestroy();
+ virtual ~Type();
private:
+ Type(Context *);
Type(const Type &);
};