diff options
author | Miao Wang <miaowang@google.com> | 2015-02-19 18:14:46 -0800 |
---|---|---|
committer | Miao Wang <miaowang@google.com> | 2015-02-23 16:33:07 -0800 |
commit | cc8cea7477352898921044483a6c803e25d02665 (patch) | |
tree | a45084bbf8be9f8f591e4512bdef7cd55abefbdf | |
parent | e9c79f66478170e4e45e49c71f5e9324842916cf (diff) | |
download | rs-cc8cea7477352898921044483a6c803e25d02665.tar.gz |
Fix the bug for AllocationRead() that cannot handle 3d Allocation
correctly.
Add the following functions to make it symmetric for read and write.
- AllocationElementData
- AllocationElementRead
- Allocation3DRead
Change-Id: I8c89b5e3474c4c3c70e9795843a76e61f1f90f6a
-rw-r--r-- | cpp/rsDispatch.cpp | 15 | ||||
-rw-r--r-- | cpp/rsDispatch.h | 6 | ||||
-rw-r--r-- | driver/rsdAllocation.cpp | 26 | ||||
-rw-r--r-- | driver/rsdAllocation.h | 17 | ||||
-rw-r--r-- | driver/rsdCore.cpp | 4 | ||||
-rw-r--r-- | rs.spec | 32 | ||||
-rw-r--r-- | rsAllocation.cpp | 71 | ||||
-rw-r--r-- | rsAllocation.h | 7 | ||||
-rw-r--r-- | rs_hal.h | 10 |
9 files changed, 134 insertions, 54 deletions
diff --git a/cpp/rsDispatch.cpp b/cpp/rsDispatch.cpp index e0d67883..6f379d09 100644 --- a/cpp/rsDispatch.cpp +++ b/cpp/rsDispatch.cpp @@ -389,6 +389,21 @@ bool loadSymbols(void* handle, dispatchTable& dispatchTab, int device_api) { LOG_API("Couldn't initialize dispatchTab.ScriptGroup2Create"); return false; } + dispatchTab.AllocationElementData = (AllocationElementDataFnPtr)dlsym(handle, "rsAllocationElementData"); + if (dispatchTab.AllocationElementData == NULL) { + LOG_API("Couldn't initialize dispatchTab.AllocationElementData"); + return false; + } + dispatchTab.AllocationElementRead = (AllocationElementReadFnPtr)dlsym(handle, "rsAllocationElementRead"); + if (dispatchTab.AllocationElementRead == NULL) { + LOG_API("Couldn't initialize dispatchTab.AllocationElementRead"); + return false; + } + dispatchTab.Allocation3DRead = (Allocation3DReadFnPtr)dlsym(handle, "rsAllocation3DRead"); + if (dispatchTab.Allocation3DRead == NULL) { + LOG_API("Couldn't initialize dispatchTab.Allocation3DRead"); + return false; + } } return true; diff --git a/cpp/rsDispatch.h b/cpp/rsDispatch.h index c1c8d77f..5bda7c01 100644 --- a/cpp/rsDispatch.h +++ b/cpp/rsDispatch.h @@ -55,12 +55,15 @@ typedef RsElement (*ElementCreate2FnPtr) (RsContext, const RsElement*, size_t, c typedef void (*AllocationCopyToBitmapFnPtr) (RsContext, RsAllocation, void*, size_t); typedef void (*Allocation1DDataFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, const void*, size_t); typedef void (*Allocation1DElementDataFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, const void*, size_t, size_t); +typedef void (*AllocationElementDataFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, uint32_t, const void*, size_t, size_t); typedef void (*Allocation2DDataFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, RsAllocationCubemapFace, uint32_t, uint32_t, const void*, size_t, size_t); typedef void (*Allocation3DDataFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, const void*, size_t, size_t); typedef void (*AllocationGenerateMipmapsFnPtr) (RsContext, RsAllocation); typedef void (*AllocationReadFnPtr) (RsContext, RsAllocation, void*, size_t); typedef void (*Allocation1DReadFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, void*, size_t); +typedef void (*AllocationElementReadFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, uint32_t, void*, size_t, size_t); typedef void (*Allocation2DReadFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, RsAllocationCubemapFace, uint32_t, uint32_t, void*, size_t, size_t); +typedef void (*Allocation3DReadFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, void*, size_t, size_t); typedef void (*AllocationSyncAllFnPtr) (RsContext, RsAllocation, RsAllocationUsageType); typedef void (*AllocationResize1DFnPtr) (RsContext, RsAllocation, uint32_t); typedef void (*AllocationCopy2DRangeFnPtr) (RsContext, RsAllocation, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, RsAllocation, uint32_t, uint32_t, uint32_t, uint32_t); @@ -134,12 +137,15 @@ struct dispatchTable { AllocationCopyToBitmapFnPtr AllocationCopyToBitmap; Allocation1DDataFnPtr Allocation1DData; Allocation1DElementDataFnPtr Allocation1DElementData; + AllocationElementDataFnPtr AllocationElementData; Allocation2DDataFnPtr Allocation2DData; Allocation3DDataFnPtr Allocation3DData; AllocationGenerateMipmapsFnPtr AllocationGenerateMipmaps; AllocationReadFnPtr AllocationRead; Allocation1DReadFnPtr Allocation1DRead; + AllocationElementReadFnPtr AllocationElementRead; Allocation2DReadFnPtr Allocation2DRead; + Allocation3DReadFnPtr Allocation3DRead; AllocationSyncAllFnPtr AllocationSyncAll; AllocationResize1DFnPtr AllocationResize1D; AllocationCopy2DRangeFnPtr AllocationCopy2DRange; diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp index f56ab56c..bbf73fb5 100644 --- a/driver/rsdAllocation.cpp +++ b/driver/rsdAllocation.cpp @@ -1114,13 +1114,12 @@ void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc, srcXoff, srcYoff, srcZoff, srcLod); } -void rsdAllocationElementData1D(const Context *rsc, const Allocation *alloc, - uint32_t x, - const void *data, uint32_t cIdx, size_t sizeBytes) { +void rsdAllocationElementData(const Context *rsc, const Allocation *alloc, + uint32_t x, uint32_t y, uint32_t z, + const void *data, uint32_t cIdx, size_t sizeBytes) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; - size_t eSize = alloc->mHal.state.elementSizeBytes; - uint8_t * ptr = GetOffsetPtr(alloc, x, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X); + uint8_t * ptr = GetOffsetPtr(alloc, x, y, z, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X); const Element * e = alloc->mHal.state.type->getElement()->getField(cIdx); ptr += alloc->mHal.state.type->getElement()->getFieldOffsetBytes(cIdx); @@ -1134,24 +1133,17 @@ void rsdAllocationElementData1D(const Context *rsc, const Allocation *alloc, drv->uploadDeferred = true; } -void rsdAllocationElementData2D(const Context *rsc, const Allocation *alloc, - uint32_t x, uint32_t y, - const void *data, uint32_t cIdx, size_t sizeBytes) { +void rsdAllocationElementRead(const Context *rsc, const Allocation *alloc, + uint32_t x, uint32_t y, uint32_t z, + void *data, uint32_t cIdx, size_t sizeBytes) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; - size_t eSize = alloc->mHal.state.elementSizeBytes; - uint8_t * ptr = GetOffsetPtr(alloc, x, y, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X); + uint8_t * ptr = GetOffsetPtr(alloc, x, y, z, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X); const Element * e = alloc->mHal.state.type->getElement()->getField(cIdx); ptr += alloc->mHal.state.type->getElement()->getFieldOffsetBytes(cIdx); - if (alloc->mHal.state.hasReferences) { - e->incRefs(data); - e->decRefs(ptr); - } - - memcpy(ptr, data, sizeBytes); - drv->uploadDeferred = true; + memcpy(data, ptr, sizeBytes); } static void mip565(const Allocation *alloc, int lod, RsAllocationCubemapFace face) { diff --git a/driver/rsdAllocation.h b/driver/rsdAllocation.h index 0b6d8bf1..eff5e302 100644 --- a/driver/rsdAllocation.h +++ b/driver/rsdAllocation.h @@ -161,14 +161,15 @@ void rsdAllocationData3D_alloc(const android::renderscript::Context *rsc, uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, uint32_t srcLod); -void rsdAllocationElementData1D(const android::renderscript::Context *rsc, - const android::renderscript::Allocation *alloc, - uint32_t x, - const void *data, uint32_t elementOff, size_t sizeBytes); -void rsdAllocationElementData2D(const android::renderscript::Context *rsc, - const android::renderscript::Allocation *alloc, - uint32_t x, uint32_t y, - const void *data, uint32_t elementOff, size_t sizeBytes); +void rsdAllocationElementData(const android::renderscript::Context *rsc, + const android::renderscript::Allocation *alloc, + uint32_t x, uint32_t y, uint32_t z, + const void *data, uint32_t elementOff, size_t sizeBytes); + +void rsdAllocationElementRead(const android::renderscript::Context *rsc, + const android::renderscript::Allocation *alloc, + uint32_t x, uint32_t y, uint32_t z, + void *data, uint32_t elementOff, size_t sizeBytes); void rsdAllocationGenerateMipmaps(const android::renderscript::Context *rsc, const android::renderscript::Allocation *alloc); diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp index 8812446e..5390faf2 100644 --- a/driver/rsdCore.cpp +++ b/driver/rsdCore.cpp @@ -108,8 +108,8 @@ static RsdHalFunctions FunctionTable = { rsdAllocationData1D_alloc, rsdAllocationData2D_alloc, rsdAllocationData3D_alloc, - rsdAllocationElementData1D, - rsdAllocationElementData2D, + rsdAllocationElementData, + rsdAllocationElementRead, rsdAllocationGenerateMipmaps, rsdAllocationUpdateCachedObject, rsdAllocationAdapterOffset @@ -174,6 +174,16 @@ Allocation1DElementData { param size_t comp_offset } +AllocationElementData { + param RsAllocation va + param uint32_t x + param uint32_t y + param uint32_t z + param uint32_t lod + param const void *data + param size_t comp_offset + } + Allocation2DData { param RsAllocation va param uint32_t xoff @@ -216,6 +226,16 @@ Allocation1DRead { param void *data } +AllocationElementRead { + param RsAllocation va + param uint32_t x + param uint32_t y + param uint32_t z + param uint32_t lod + param void *data + param size_t comp_offset + } + Allocation2DRead { param RsAllocation va param uint32_t xoff @@ -228,6 +248,18 @@ Allocation2DRead { param size_t stride } +Allocation3DRead { + param RsAllocation va + param uint32_t xoff + param uint32_t yoff + param uint32_t zoff + param uint32_t lod + param uint32_t w + param uint32_t h + param uint32_t d + param void *data + param size_t stride + } AllocationSyncAll { param RsAllocation va diff --git a/rsAllocation.cpp b/rsAllocation.cpp index 386d86fb..1d3daaf6 100644 --- a/rsAllocation.cpp +++ b/rsAllocation.cpp @@ -256,17 +256,27 @@ void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, } -void Allocation::elementData(Context *rsc, uint32_t x, const void *data, - uint32_t cIdx, size_t sizeBytes) { +void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, uint32_t z, + const void *data, uint32_t cIdx, size_t sizeBytes) { size_t eSize = mHal.state.elementSizeBytes; - if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { - rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); + if (x >= mHal.drvState.lod[0].dimX) { + rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); return; } - if (x >= mHal.drvState.lod[0].dimX) { - rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); + if (y > 0 && y >= mHal.drvState.lod[0].dimY) { + rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Y offset out of range."); + return; + } + + if (z > 0 && z >= mHal.drvState.lod[0].dimZ) { + rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Z offset out of range."); + return; + } + + if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { + rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); return; } @@ -277,12 +287,12 @@ void Allocation::elementData(Context *rsc, uint32_t x, const void *data, return; } - rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes); + rsc->mHal.funcs.allocation.elementData(rsc, this, x, y, z, data, cIdx, sizeBytes); sendDirty(rsc); } -void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, - const void *data, uint32_t cIdx, size_t sizeBytes) { +void Allocation::elementRead(Context *rsc, uint32_t x, uint32_t y, uint32_t z, + void *data, uint32_t cIdx, size_t sizeBytes) { size_t eSize = mHal.state.elementSizeBytes; if (x >= mHal.drvState.lod[0].dimX) { @@ -290,8 +300,13 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, return; } - if (y >= mHal.drvState.lod[0].dimY) { - rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); + if (y > 0 && y >= mHal.drvState.lod[0].dimY) { + rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Y offset out of range."); + return; + } + + if (z > 0 && z >= mHal.drvState.lod[0].dimZ) { + rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Z offset out of range."); return; } @@ -307,8 +322,7 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, return; } - rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes); - sendDirty(rsc); + rsc->mHal.funcs.allocation.elementRead(rsc, this, x, y, z, data, cIdx, sizeBytes); } void Allocation::addProgramToDirty(const Program *p) { @@ -653,16 +667,16 @@ void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t a->data(rsc, xoff, lod, count, data, sizeBytes); } -void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face, - const void *data, size_t sizeBytes, size_t eoff) { +void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, + uint32_t lod, const void *data, size_t sizeBytes, size_t eoff) { Allocation *a = static_cast<Allocation *>(va); - a->elementData(rsc, x, y, data, eoff, sizeBytes); + a->elementData(rsc, x, 0, 0, data, eoff, sizeBytes); } -void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod, - const void *data, size_t sizeBytes, size_t eoff) { +void rsi_AllocationElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t z, + uint32_t lod, const void *data, size_t sizeBytes, size_t eoff) { Allocation *a = static_cast<Allocation *>(va); - a->elementData(rsc, x, data, eoff, sizeBytes); + a->elementData(rsc, x, y, z, data, eoff, sizeBytes); } void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, @@ -681,7 +695,10 @@ void rsi_Allocation3DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) { Allocation *a = static_cast<Allocation *>(va); const Type * t = a->getType(); - if(t->getDimY()) { + if(t->getDimZ()) { + a->read(rsc, 0, 0, 0, 0, t->getDimX(), t->getDimY(), t->getDimZ(), + data, sizeBytes, 0); + } else if(t->getDimY()) { a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, t->getDimX(), t->getDimY(), data, sizeBytes, 0); } else { @@ -840,6 +857,12 @@ void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t rsc->mHal.funcs.allocation.read1D(rsc, a, xoff, lod, count, data, sizeBytes); } +void rsi_AllocationElementRead(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t z, + uint32_t lod, void *data, size_t sizeBytes, size_t eoff) { + Allocation *a = static_cast<Allocation *>(va); + a->elementRead(rsc, x, y, z, data, eoff, sizeBytes); +} + void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride) { @@ -847,6 +870,14 @@ void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); } +void rsi_Allocation3DRead(Context *rsc, RsAllocation va, + uint32_t xoff, uint32_t yoff, uint32_t zoff, + uint32_t lod, uint32_t w, uint32_t h, uint32_t d, + void *data, size_t sizeBytes, size_t stride) { + Allocation *a = static_cast<Allocation *>(va); + a->read(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); +} + RsAllocation rsi_AllocationAdapterCreate(Context *rsc, RsType vwindow, RsAllocation vbase) { diff --git a/rsAllocation.h b/rsAllocation.h index 10009575..a06e28d9 100644 --- a/rsAllocation.h +++ b/rsAllocation.h @@ -138,11 +138,12 @@ public: void read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride); - void elementData(Context *rsc, uint32_t x, - const void *data, uint32_t elementOff, size_t sizeBytes); - void elementData(Context *rsc, uint32_t x, uint32_t y, + void elementData(Context *rsc, uint32_t x, uint32_t y, uint32_t z, const void *data, uint32_t elementOff, size_t sizeBytes); + void elementRead(Context *rsc, uint32_t x, uint32_t y, uint32_t z, + void *data, uint32_t elementOff, size_t sizeBytes); + void addProgramToDirty(const Program *); void removeProgramToDirty(const Program *); @@ -236,10 +236,12 @@ typedef struct { uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, uint32_t srcLod); - void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, - const void *data, uint32_t elementOff, size_t sizeBytes); - void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, - const void *data, uint32_t elementOff, size_t sizeBytes); + void (*elementData)(const Context *rsc, const Allocation *alloc, + uint32_t x, uint32_t y, uint32_t z, + const void *data, uint32_t elementOff, size_t sizeBytes); + void (*elementRead)(const Context *rsc, const Allocation *alloc, + uint32_t x, uint32_t y, uint32_t z, + void *data, uint32_t elementOff, size_t sizeBytes); void (*generateMipmaps)(const Context *rsc, const Allocation *alloc); |