Lines Matching defs:alloc

92 uint8_t *GetOffsetPtr(const android::renderscript::Allocation *alloc,
95 uint8_t *ptr = (uint8_t *)alloc->mHal.drvState.lod[lod].mallocPtr;
96 ptr += face * alloc->mHal.drvState.faceOffset;
97 ptr += zoff * alloc->mHal.drvState.lod[lod].dimY * alloc->mHal.drvState.lod[lod].stride;
98 ptr += yoff * alloc->mHal.drvState.lod[lod].stride;
99 ptr += xoff * alloc->mHal.state.elementSizeBytes;
104 static void Update2DTexture(const Context *rsc, const Allocation *alloc, const void *ptr,
108 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
114 if (alloc->mHal.state.hasFaces) {
123 static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool isFirstUpload) {
124 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
130 if (alloc->mHal.state.hasFaces) {
136 for (uint32_t lod = 0; lod < alloc->mHal.state.type->getLODCount(); lod++) {
137 const uint8_t *p = GetOffsetPtr(alloc, 0, 0, 0, lod, (RsAllocationCubemapFace)face);
140 if (alloc->mHal.state.hasFaces) {
146 alloc->mHal.state.type->getLODDimX(lod),
147 alloc->mHal.state.type->getLODDimY(lod),
151 alloc->mHal.state.type->getLODDimX(lod),
152 alloc->mHal.state.type->getLODDimY(lod),
158 if (alloc->mHal.state.mipmapControl == RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE) {
165 static void UploadToTexture(const Context *rsc, const Allocation *alloc) {
167 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
169 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) {
180 if (!alloc->mHal.drvState.lod[0].mallocPtr) {
191 Upload2DTexture(rsc, alloc, isFirstUpload);
193 if (!(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
194 if (alloc->mHal.drvState.lod[0].mallocPtr) {
195 free(alloc->mHal.drvState.lod[0].mallocPtr);
196 alloc->mHal.drvState.lod[0].mallocPtr = NULL;
203 static void AllocateRenderTarget(const Context *rsc, const Allocation *alloc) {
205 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
222 alloc->mHal.drvState.lod[0].dimX, alloc->mHal.drvState.lod[0].dimY);
228 static void UploadToBufferObject(const Context *rsc, const Allocation *alloc) {
230 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
232 rsAssert(!alloc->mHal.state.type->getDimY());
233 rsAssert(!alloc->mHal.state.type->getDimZ());
235 //alloc->mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX;
247 alloc->mHal.state.type->getPackedSizeBytes(),
248 alloc->mHal.drvState.lod[0].mallocPtr, GL_DYNAMIC_DRAW);
303 static size_t AllocationBuildPointerTable(const Context *rsc, const Allocation *alloc,
305 alloc->mHal.drvState.lod[0].dimX = type->getDimX();
306 alloc->mHal.drvState.lod[0].dimY = type->getDimY();
307 alloc->mHal.drvState.lod[0].dimZ = type->getDimZ();
308 alloc->mHal.drvState.lod[0].mallocPtr = 0;
310 size_t stride = alloc->mHal.drvState.lod[0].dimX * type->getElementSizeBytes();
311 alloc->mHal.drvState.lod[0].stride = rsRound(stride, 16);
312 alloc->mHal.drvState.lodCount = type->getLODCount();
313 alloc->mHal.drvState.faceCount = type->getDimFaces();
318 size_t o = alloc->mHal.drvState.lod[0].stride * rsMax(alloc->mHal.drvState.lod[0].dimY, 1u) *
319 rsMax(alloc->mHal.drvState.lod[0].dimZ, 1u);
320 if (alloc->mHal.state.yuv) {
321 o += DeriveYUVLayout(alloc->mHal.state.yuv, &alloc->mHal.drvState);
323 for (uint32_t ct = 1; ct < alloc->mHal.drvState.lodCount; ct++) {
324 offsets[ct] = (size_t)alloc->mHal.drvState.lod[ct].mallocPtr;
326 } else if(alloc->mHal.drvState.lodCount > 1) {
327 uint32_t tx = alloc->mHal.drvState.lod[0].dimX;
328 uint32_t ty = alloc->mHal.drvState.lod[0].dimY;
329 uint32_t tz = alloc->mHal.drvState.lod[0].dimZ;
330 for (uint32_t lod=1; lod < alloc->mHal.drvState.lodCount; lod++) {
331 alloc->mHal.drvState.lod[lod].dimX = tx;
332 alloc->mHal.drvState.lod[lod].dimY = ty;
333 alloc->mHal.drvState.lod[lod].dimZ = tz;
334 alloc->mHal.drvState.lod[lod].stride =
337 o += alloc->mHal.drvState.lod[lod].stride * rsMax(ty, 1u) * rsMax(tz, 1u);
344 alloc->mHal.drvState.faceOffset = o;
346 alloc->mHal.drvState.lod[0].mallocPtr = ptr;
347 for (uint32_t lod=1; lod < alloc->mHal.drvState.lodCount; lod++) {
348 alloc->mHal.drvState.lod[lod].mallocPtr = ptr + offsets[lod];
351 size_t allocSize = alloc->mHal.drvState.faceOffset;
352 if(alloc->mHal.drvState.faceCount) {
371 bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) {
376 alloc->mHal.drv = drv;
379 size_t allocSize = AllocationBuildPointerTable(rsc, alloc, alloc->getType(), NULL);
382 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT) {
384 } else if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) {
387 } else if (alloc->mHal.state.userProvidedPtr != NULL) {
390 if (!(alloc->mHal.state.usageFlags == (RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED) ||
391 alloc->mHal.state.usageFlags == (RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE))) {
395 if (alloc->getType()->getDimLOD() || alloc->getType()->getDimFaces()) {
402 if (((alloc->getType()->getDimX() * alloc->getType()->getElement()->getSizeBytes()) % 16) != 0) {
408 alloc->mHal.drv = NULL;
415 ptr = (uint8_t*)alloc->mHal.state.userProvidedPtr;
420 alloc->mHal.drv = NULL;
426 size_t verifySize = AllocationBuildPointerTable(rsc, alloc, alloc->getType(), ptr);
433 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) {
434 if (alloc->mHal.state.hasFaces) {
440 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) {
447 drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType());
448 drv->glFormat = rsdKindToGLFormat(alloc->mHal.state.type->getElement()->getComponent().getKind());
454 if (alloc->mHal.state.usageFlags & ~RS_ALLOCATION_USAGE_SCRIPT) {
462 if ((alloc->mHal.state.userProvidedPtr != 0) && (drv->useUserProvidedPtr == false)) {
463 rsdAllocationData2D(rsc, alloc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, alloc->getType()->getDimX(), alloc->getType()->getDimY(), alloc->mHal.state.userProvidedPtr, allocSize, 0);
468 ALOGE("pointer for allocation: %p", alloc);
469 ALOGE("pointer for allocation.drv: %p", &alloc->mHal.drv);
476 void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) {
477 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
496 if (alloc->mHal.drvState.lod[0].mallocPtr) {
499 !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) &&
500 !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT)) {
501 free(alloc->mHal.drvState.lod[0].mallocPtr);
503 alloc->mHal.drvState.lod[0].mallocPtr = NULL;
512 if ((alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT) &&
513 (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
515 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
530 alloc->mHal.drv = NULL;
533 void rsdAllocationResize(const Context *rsc, const Allocation *alloc,
535 const uint32_t oldDimX = alloc->mHal.drvState.lod[0].dimX;
539 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SHARED) {
543 void * oldPtr = alloc->mHal.drvState.lod[0].mallocPtr;
545 size_t s = AllocationBuildPointerTable(rsc, alloc, newType, NULL);
548 size_t verifySize = AllocationBuildPointerTable(rsc, alloc, newType, ptr);
555 size_t stride = alloc->mHal.state.elementSizeBytes;
556 memset(((uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr) + stride * oldDimX,
561 static void rsdAllocationSyncFromFBO(const Context *rsc, const Allocation *alloc) {
563 if (!alloc->getIsScript()) {
570 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
577 drv->readBackFBO->setDimensions(alloc->getType()->getDimX(),
578 alloc->getType()->getDimY());
585 RSD_CALL_GL(glReadPixels, 0, 0, alloc->mHal.drvState.lod[0].dimX,
586 alloc->mHal.drvState.lod[0].dimY,
587 drv->glFormat, drv->glType, alloc->mHal.drvState.lod[0].mallocPtr);
595 void rsdAllocationSyncAll(const Context *rsc, const Allocation *alloc,
597 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
600 if(!alloc->getIsRenderTarget()) {
604 } else if (alloc->getType()->getElement()->getKind() != RS_KIND_PIXEL_RGBA) {
608 rsdAllocationSyncFromFBO(rsc, alloc);
615 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) {
616 UploadToTexture(rsc, alloc);
618 if ((alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) &&
619 !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT)) {
620 AllocateRenderTarget(rsc, alloc);
623 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) {
624 UploadToBufferObject(rsc, alloc);
627 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SHARED) {
640 void rsdAllocationMarkDirty(const Context *rsc, const Allocation *alloc) {
641 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
646 static bool IoGetBuffer(const Context *rsc, Allocation *alloc, ANativeWindow *nw) {
647 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
663 alloc->mHal.drvState.lod[0].mallocPtr = dst;
664 alloc->mHal.drvState.lod[0].stride = drv->wndBuffer->stride * alloc->mHal.state.elementSizeBytes;
665 rsAssert((alloc->mHal.drvState.lod[0].stride & 0xf) == 0);
671 void rsdAllocationSetSurface(const Context *rsc, Allocation *alloc, ANativeWindow *nw) {
673 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
680 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) {
702 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) {
705 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) {
721 r = native_window_set_buffers_dimensions(nw, alloc->mHal.drvState.lod[0].dimX,
722 alloc->mHal.drvState.lod[0].dimY);
729 const Element *e = alloc->mHal.state.type->getElement();
741 IoGetBuffer(rsc, alloc, nw);
757 void rsdAllocationIoSend(const Context *rsc, Allocation *alloc) {
759 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
761 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) {
767 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) {
776 IoGetBuffer(rsc, alloc, nw);
785 void rsdAllocationIoReceive(const Context *rsc, Allocation *alloc) {
787 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
788 if (!(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
795 void rsdAllocationData1D(const Context *rsc, const Allocation *alloc,
798 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
800 const size_t eSize = alloc->mHal.state.type->getElementSizeBytes();
801 uint8_t * ptr = GetOffsetPtr(alloc, xoff, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
806 if (alloc->mHal.state.hasReferences) {
807 alloc->incRefs(data, count);
808 alloc->decRefs(ptr, count);
815 void rsdAllocationData2D(const Context *rsc, const Allocation *alloc,
818 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
820 size_t eSize = alloc->mHal.state.elementSizeBytes;
826 if (alloc->mHal.drvState.lod[0].mallocPtr) {
828 uint8_t *dst = GetOffsetPtr(alloc, xoff, yoff, 0, lod, face);
837 if (alloc->mHal.state.hasReferences) {
838 alloc->incRefs(src, w);
839 alloc->decRefs(dst, w);
843 dst += alloc->mHal.drvState.lod[lod].stride;
845 if (alloc->mHal.state.yuv) {
849 if (alloc->mHal.state.yuv == HAL_PIXEL_FORMAT_YV12) {
852 } else if (alloc->mHal.state.yuv == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
858 uint8_t *dst = GetOffsetPtr(alloc, xoff, yoff, 0, lod, face);
862 src += alloc->mHal.drvState.lod[lod].stride;
863 dst += alloc->mHal.drvState.lod[lod].stride;
871 Update2DTexture(rsc, alloc, data, xoff, yoff, lod, face, w, h);
875 void rsdAllocationData3D(const Context *rsc, const Allocation *alloc,
880 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
882 uint32_t eSize = alloc->mHal.state.elementSizeBytes;
888 if (alloc->mHal.drvState.lod[0].mallocPtr) {
891 uint8_t *dst = GetOffsetPtr(alloc, xoff, yoff, z, lod,
901 if (alloc->mHal.state.hasReferences) {
902 alloc->incRefs(src, w);
903 alloc->decRefs(dst, w);
907 dst += alloc->mHal.drvState.lod[lod].stride;
914 void rsdAllocationRead1D(const Context *rsc, const Allocation *alloc,
917 const size_t eSize = alloc->mHal.state.type->getElementSizeBytes();
918 const uint8_t * ptr = GetOffsetPtr(alloc, xoff, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
926 void rsdAllocationRead2D(const Context *rsc, const Allocation *alloc,
929 size_t eSize = alloc->mHal.state.elementSizeBytes;
935 if (alloc->mHal.drvState.lod[0].mallocPtr) {
937 const uint8_t *src = GetOffsetPtr(alloc, xoff, yoff, 0, lod, face);
947 src += alloc->mHal.drvState.lod[lod].stride;
955 void rsdAllocationRead3D(const Context *rsc, const Allocation *alloc,
959 uint32_t eSize = alloc->mHal.state.elementSizeBytes;
965 if (alloc->mHal.drvState.lod[0].mallocPtr) {
968 const uint8_t *src = GetOffsetPtr(alloc, xoff, yoff, z, lod,
979 src += alloc->mHal.drvState.lod[lod].stride;
986 const android::renderscript::Allocation *alloc) {
987 return alloc->mHal.drvState.lod[0].mallocPtr;
991 const android::renderscript::Allocation *alloc) {
1077 void rsdAllocationElementData1D(const Context *rsc, const Allocation *alloc,
1080 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
1082 size_t eSize = alloc->mHal.state.elementSizeBytes;
1083 uint8_t * ptr = GetOffsetPtr(alloc, x, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
1085 const Element * e = alloc->mHal.state.type->getElement()->getField(cIdx);
1086 ptr += alloc->mHal.state.type->getElement()->getFieldOffsetBytes(cIdx);
1088 if (alloc->mHal.state.hasReferences) {
1097 void rsdAllocationElementData2D(const Context *rsc, const Allocation *alloc,
1100 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
1102 size_t eSize = alloc->mHal.state.elementSizeBytes;
1103 uint8_t * ptr = GetOffsetPtr(alloc, x, y, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
1105 const Element * e = alloc->mHal.state.type->getElement()->getField(cIdx);
1106 ptr += alloc->mHal.state.type->getElement()->getFieldOffsetBytes(cIdx);
1108 if (alloc->mHal.state.hasReferences) {
1117 static void mip565(const Allocation *alloc, int lod, RsAllocationCubemapFace face) {
1118 uint32_t w = alloc->mHal.drvState.lod[lod + 1].dimX;
1119 uint32_t h = alloc->mHal.drvState.lod[lod + 1].dimY;
1122 uint16_t *oPtr = (uint16_t *)GetOffsetPtr(alloc, 0, y, 0, lod + 1, face);
1123 const uint16_t *i1 = (uint16_t *)GetOffsetPtr(alloc, 0, 0, y*2, lod, face);
1124 const uint16_t *i2 = (uint16_t *)GetOffsetPtr(alloc, 0, 0, y*2+1, lod, face);
1135 static void mip8888(const Allocation *alloc, int lod, RsAllocationCubemapFace face) {
1136 uint32_t w = alloc->mHal.drvState.lod[lod + 1].dimX;
1137 uint32_t h = alloc->mHal.drvState.lod[lod + 1].dimY;
1140 uint32_t *oPtr = (uint32_t *)GetOffsetPtr(alloc, 0, y, 0, lod + 1, face);
1141 const uint32_t *i1 = (uint32_t *)GetOffsetPtr(alloc, 0, y*2, 0, lod, face);
1142 const uint32_t *i2 = (uint32_t *)GetOffsetPtr(alloc, 0, y*2+1, 0, lod, face);
1153 static void mip8(const Allocation *alloc, int lod, RsAllocationCubemapFace face) {
1154 uint32_t w = alloc->mHal.drvState.lod[lod + 1].dimX;
1155 uint32_t h = alloc->mHal.drvState.lod[lod + 1].dimY;
1158 uint8_t *oPtr = GetOffsetPtr(alloc, 0, y, 0, lod + 1, face);
1159 const uint8_t *i1 = GetOffsetPtr(alloc, 0, y*2, 0, lod, face);
1160 const uint8_t *i2 = GetOffsetPtr(alloc, 0, y*2+1, 0, lod, face);
1171 void rsdAllocationGenerateMipmaps(const Context *rsc, const Allocation *alloc) {
1172 if(!alloc->mHal.drvState.lod[0].mallocPtr) {
1175 uint32_t numFaces = alloc->getType()->getDimFaces() ? 6 : 1;
1177 for (uint32_t lod=0; lod < (alloc->getType()->getLODCount() -1); lod++) {
1178 switch (alloc->getType()->getElement()->getSizeBits()) {
1180 mip8888(alloc, lod, (RsAllocationCubemapFace)face);
1183 mip565(alloc, lod, (RsAllocationCubemapFace)face);
1186 mip8(alloc, lod, (RsAllocationCubemapFace)face);
1194 android::renderscript::Allocation *alloc)
1200 const Allocation *alloc,
1203 obj->p = alloc;
1205 if (alloc != NULL) {
1206 obj->r = alloc->mHal.drvState.lod[0].mallocPtr;
1207 obj->v1 = alloc->mHal.drv;
1208 obj->v2 = (void *)alloc->mHal.drvState.lod[0].stride;