Lines Matching refs: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;
246 RSD_CALL_GL(glBufferData, drv->glTarget, alloc->mHal.state.type->getSizeBytes(),
247 alloc->mHal.drvState.lod[0].mallocPtr, GL_DYNAMIC_DRAW);
294 static size_t AllocationBuildPointerTable(const Context *rsc, const Allocation *alloc,
296 alloc->mHal.drvState.lod[0].dimX = type->getDimX();
297 alloc->mHal.drvState.lod[0].dimY = type->getDimY();
298 alloc->mHal.drvState.lod[0].dimZ = type->getDimZ();
299 alloc->mHal.drvState.lod[0].mallocPtr = 0;
301 size_t stride = alloc->mHal.drvState.lod[0].dimX * type->getElementSizeBytes();
302 alloc->mHal.drvState.lod[0].stride = rsRound(stride, 16);
303 alloc->mHal.drvState.lodCount = type->getLODCount();
304 alloc->mHal.drvState.faceCount = type->getDimFaces();
309 size_t o = alloc->mHal.drvState.lod[0].stride * rsMax(alloc->mHal.drvState.lod[0].dimY, 1u) *
310 rsMax(alloc->mHal.drvState.lod[0].dimZ, 1u);
311 if(alloc->mHal.drvState.lodCount > 1) {
312 uint32_t tx = alloc->mHal.drvState.lod[0].dimX;
313 uint32_t ty = alloc->mHal.drvState.lod[0].dimY;
314 uint32_t tz = alloc->mHal.drvState.lod[0].dimZ;
315 for (uint32_t lod=1; lod < alloc->mHal.drvState.lodCount; lod++) {
316 alloc->mHal.drvState.lod[lod].dimX = tx;
317 alloc->mHal.drvState.lod[lod].dimY = ty;
318 alloc->mHal.drvState.lod[lod].dimZ = tz;
319 alloc->mHal.drvState.lod[lod].stride =
322 o += alloc->mHal.drvState.lod[lod].stride * rsMax(ty, 1u) * rsMax(tz, 1u);
327 } else if (alloc->mHal.state.yuv) {
328 o += DeriveYUVLayout(alloc->mHal.state.yuv, &alloc->mHal.drvState);
330 for (uint32_t ct = 1; ct < alloc->mHal.drvState.lodCount; ct++) {
331 offsets[ct] = (size_t)alloc->mHal.drvState.lod[ct].mallocPtr;
335 alloc->mHal.drvState.faceOffset = o;
337 alloc->mHal.drvState.lod[0].mallocPtr = ptr;
338 for (uint32_t lod=1; lod < alloc->mHal.drvState.lodCount; lod++) {
339 alloc->mHal.drvState.lod[lod].mallocPtr = ptr + offsets[lod];
342 size_t allocSize = alloc->mHal.drvState.faceOffset;
343 if(alloc->mHal.drvState.faceCount) {
362 bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) {
367 alloc->mHal.drv = drv;
370 size_t allocSize = AllocationBuildPointerTable(rsc, alloc, alloc->getType(), NULL);
373 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT) {
375 } else if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) {
378 } else if (alloc->mHal.state.userProvidedPtr != NULL) {
381 if (!(alloc->mHal.state.usageFlags == (RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED) ||
382 alloc->mHal.state.usageFlags == (RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE))) {
386 if (alloc->getType()->getDimLOD() || alloc->getType()->getDimFaces()) {
393 if (((alloc->getType()->getDimX() * alloc->getType()->getElement()->getSizeBytes()) % 16) != 0) {
399 alloc->mHal.drv = NULL;
406 ptr = (uint8_t*)alloc->mHal.state.userProvidedPtr;
411 alloc->mHal.drv = NULL;
417 size_t verifySize = AllocationBuildPointerTable(rsc, alloc, alloc->getType(), ptr);
424 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) {
425 if (alloc->mHal.state.hasFaces) {
431 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) {
438 drv->glType = rsdTypeToGLType(alloc->mHal.state.type->getElement()->getComponent().getType());
439 drv->glFormat = rsdKindToGLFormat(alloc->mHal.state.type->getElement()->getComponent().getKind());
445 if (alloc->mHal.state.usageFlags & ~RS_ALLOCATION_USAGE_SCRIPT) {
453 if ((alloc->mHal.state.userProvidedPtr != 0) && (drv->useUserProvidedPtr == false)) {
454 rsdAllocationData2D(rsc, alloc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, alloc->getType()->getDimX(), alloc->getType()->getDimY(), alloc->mHal.state.userProvidedPtr, allocSize, 0);
460 void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) {
461 alloc->mHal.drv;
480 if (alloc->mHal.drvState.lod[0].mallocPtr) {
483 !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_INPUT) &&
484 !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT)) {
485 free(alloc->mHal.drvState.lod[0].mallocPtr);
487 alloc->mHal.drvState.lod[0].mallocPtr = NULL;
496 if ((alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT) &&
497 (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT)) {
499 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
510 alloc->mHal.drv = NULL;
513 void rsdAllocationResize(const Context *rsc, const Allocation *alloc,
515 const uint32_t oldDimX = alloc->mHal.drvState.lod[0].dimX;
519 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SHARED) {
523 void * oldPtr = alloc->mHal.drvState.lod[0].mallocPtr;
525 size_t s = AllocationBuildPointerTable(rsc, alloc, newType, NULL);
528 size_t verifySize = AllocationBuildPointerTable(rsc, alloc, newType, ptr);
535 size_t stride = alloc->mHal.state.elementSizeBytes;
536 memset(((uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr) + stride * oldDimX,
541 static void rsdAllocationSyncFromFBO(const Context *rsc, const Allocation *alloc) {
543 if (!alloc->getIsScript()) {
550 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
557 drv->readBackFBO->setDimensions(alloc->getType()->getDimX(),
558 alloc->getType()->getDimY());
565 RSD_CALL_GL(glReadPixels, 0, 0, alloc->mHal.drvState.lod[0].dimX,
566 alloc->mHal.drvState.lod[0].dimY,
567 drv->glFormat, drv->glType, alloc->mHal.drvState.lod[0].mallocPtr);
575 void rsdAllocationSyncAll(const Context *rsc, const Allocation *alloc,
577 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
580 if(!alloc->getIsRenderTarget()) {
584 } else if (alloc->getType()->getElement()->getKind() != RS_KIND_PIXEL_RGBA) {
588 rsdAllocationSyncFromFBO(rsc, alloc);
595 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) {
596 UploadToTexture(rsc, alloc);
598 if ((alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) &&
599 !(alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_IO_OUTPUT)) {
600 AllocateRenderTarget(rsc, alloc);
603 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) {
604 UploadToBufferObject(rsc, alloc);
607 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SHARED) {
614 void rsdAllocationMarkDirty(const Context *rsc, const Allocation *alloc) {
615 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
621 intptr_t ip = (intptr_t)alloc;
626 void* rsdAllocationGetSurface(const Context *rsc, const Allocation *alloc) {
628 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
637 drv->mBufferListener->alloc = alloc;
648 static bool IoGetBuffer(const Context *rsc, Allocation *alloc, ANativeWindow *nw) {
649 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
665 alloc->mHal.drvState.lod[0].mallocPtr = dst;
666 alloc->mHal.drvState.lod[0].stride = drv->wndBuffer->stride * alloc->mHal.state.elementSizeBytes;
667 rsAssert((alloc->mHal.drvState.lod[0].stride & 0xf) == 0);
673 void rsdAllocationSetSurface(const Context *rsc, Allocation *alloc, ANativeWindow *nw) {
675 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
682 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) {
715 r = native_window_set_buffers_dimensions(nw, alloc->mHal.drvState.lod[0].dimX,
716 alloc->mHal.drvState.lod[0].dimY);
723 const Element *e = alloc->mHal.state.type->getElement();
749 IoGetBuffer(rsc, alloc, nw);
765 void rsdAllocationIoSend(const Context *rsc, Allocation *alloc) {
767 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
769 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) {
775 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) {
784 IoGetBuffer(rsc, alloc, nw);
793 void rsdAllocationIoReceive(const Context *rsc, Allocation *alloc) {
795 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
797 if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) {
805 alloc->mHal.drvState.lod[0].mallocPtr = drv->lb.data;
806 alloc->mHal.drvState.lod[0].stride = drv->lb.stride *
807 alloc->mHal.state.elementSizeBytes;
809 if (alloc->mHal.state.yuv) {
810 DeriveYUVLayout(alloc->mHal.state.yuv, &alloc->mHal.drvState);
827 void rsdAllocationData1D(const Context *rsc, const Allocation *alloc,
830 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
832 const size_t eSize = alloc->mHal.state.type->getElementSizeBytes();
833 uint8_t * ptr = GetOffsetPtr(alloc, xoff, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
839 if (alloc->mHal.state.hasReferences) {
840 alloc->incRefs(data, count);
841 alloc->decRefs(ptr, count);
848 void rsdAllocationData2D(const Context *rsc, const Allocation *alloc,
851 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
853 size_t eSize = alloc->mHal.state.elementSizeBytes;
859 if (alloc->mHal.drvState.lod[0].mallocPtr) {
861 uint8_t *dst = GetOffsetPtr(alloc, xoff, yoff, 0, lod, face);
870 if (alloc->mHal.state.hasReferences) {
871 alloc->incRefs(src, w);
872 alloc->decRefs(dst, w);
876 dst += alloc->mHal.drvState.lod[lod].stride;
878 if (alloc->mHal.state.yuv) {
880 while (alloc->mHal.drvState.lod[lod].mallocPtr) {
881 size_t lineSize = alloc->mHal.drvState.lod[lod].dimX;
882 uint8_t *dst = GetOffsetPtr(alloc, xoff, yoff, 0, lod, face);
887 dst += alloc->mHal.drvState.lod[lod].stride;
895 Update2DTexture(rsc, alloc, data, xoff, yoff, lod, face, w, h);
899 void rsdAllocationData3D(const Context *rsc, const Allocation *alloc,
904 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
906 uint32_t eSize = alloc->mHal.state.elementSizeBytes;
912 if (alloc->mHal.drvState.lod[0].mallocPtr) {
915 uint8_t *dst = GetOffsetPtr(alloc, xoff, yoff, z, lod,
925 if (alloc->mHal.state.hasReferences) {
926 alloc->incRefs(src, w);
927 alloc->decRefs(dst, w);
931 dst += alloc->mHal.drvState.lod[lod].stride;
938 void rsdAllocationRead1D(const Context *rsc, const Allocation *alloc,
941 const size_t eSize = alloc->mHal.state.type->getElementSizeBytes();
942 const uint8_t * ptr = GetOffsetPtr(alloc, xoff, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
950 void rsdAllocationRead2D(const Context *rsc, const Allocation *alloc,
953 size_t eSize = alloc->mHal.state.elementSizeBytes;
959 if (alloc->mHal.drvState.lod[0].mallocPtr) {
961 const uint8_t *src = GetOffsetPtr(alloc, xoff, yoff, 0, lod, face);
971 src += alloc->mHal.drvState.lod[lod].stride;
979 void rsdAllocationRead3D(const Context *rsc, const Allocation *alloc,
983 uint32_t eSize = alloc->mHal.state.elementSizeBytes;
989 if (alloc->mHal.drvState.lod[0].mallocPtr) {
992 const uint8_t *src = GetOffsetPtr(alloc, xoff, yoff, z, lod,
1003 src += alloc->mHal.drvState.lod[lod].stride;
1010 const android::renderscript::Allocation *alloc) {
1011 return alloc->mHal.drvState.lod[0].mallocPtr;
1015 const android::renderscript::Allocation *alloc) {
1101 void rsdAllocationElementData1D(const Context *rsc, const Allocation *alloc,
1104 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
1106 size_t eSize = alloc->mHal.state.elementSizeBytes;
1107 uint8_t * ptr = GetOffsetPtr(alloc, x, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
1109 const Element * e = alloc->mHal.state.type->getElement()->getField(cIdx);
1110 ptr += alloc->mHal.state.type->getElement()->getFieldOffsetBytes(cIdx);
1112 if (alloc->mHal.state.hasReferences) {
1121 void rsdAllocationElementData2D(const Context *rsc, const Allocation *alloc,
1124 DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv;
1126 size_t eSize = alloc->mHal.state.elementSizeBytes;
1127 uint8_t * ptr = GetOffsetPtr(alloc, x, y, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
1129 const Element * e = alloc->mHal.state.type->getElement()->getField(cIdx);
1130 ptr += alloc->mHal.state.type->getElement()->getFieldOffsetBytes(cIdx);
1132 if (alloc->mHal.state.hasReferences) {
1141 static void mip565(const Allocation *alloc, int lod, RsAllocationCubemapFace face) {
1142 uint32_t w = alloc->mHal.drvState.lod[lod + 1].dimX;
1143 uint32_t h = alloc->mHal.drvState.lod[lod + 1].dimY;
1146 uint16_t *oPtr = (uint16_t *)GetOffsetPtr(alloc, 0, y, 0, lod + 1, face);
1147 const uint16_t *i1 = (uint16_t *)GetOffsetPtr(alloc, 0, 0, y*2, lod, face);
1148 const uint16_t *i2 = (uint16_t *)GetOffsetPtr(alloc, 0, 0, y*2+1, lod, face);
1159 static void mip8888(const Allocation *alloc, int lod, RsAllocationCubemapFace face) {
1160 uint32_t w = alloc->mHal.drvState.lod[lod + 1].dimX;
1161 uint32_t h = alloc->mHal.drvState.lod[lod + 1].dimY;
1164 uint32_t *oPtr = (uint32_t *)GetOffsetPtr(alloc, 0, y, 0, lod + 1, face);
1165 const uint32_t *i1 = (uint32_t *)GetOffsetPtr(alloc, 0, y*2, 0, lod, face);
1166 const uint32_t *i2 = (uint32_t *)GetOffsetPtr(alloc, 0, y*2+1, 0, lod, face);
1177 static void mip8(const Allocation *alloc, int lod, RsAllocationCubemapFace face) {
1178 uint32_t w = alloc->mHal.drvState.lod[lod + 1].dimX;
1179 uint32_t h = alloc->mHal.drvState.lod[lod + 1].dimY;
1182 uint8_t *oPtr = GetOffsetPtr(alloc, 0, y, 0, lod + 1, face);
1183 const uint8_t *i1 = GetOffsetPtr(alloc, 0, y*2, 0, lod, face);
1184 const uint8_t *i2 = GetOffsetPtr(alloc, 0, y*2+1, 0, lod, face);
1195 void rsdAllocationGenerateMipmaps(const Context *rsc, const Allocation *alloc) {
1196 if(!alloc->mHal.drvState.lod[0].mallocPtr) {
1199 uint32_t numFaces = alloc->getType()->getDimFaces() ? 6 : 1;
1201 for (uint32_t lod=0; lod < (alloc->getType()->getLODCount() -1); lod++) {
1202 switch (alloc->getType()->getElement()->getSizeBits()) {
1204 mip8888(alloc, lod, (RsAllocationCubemapFace)face);
1207 mip565(alloc, lod, (RsAllocationCubemapFace)face);
1210 mip8(alloc, lod, (RsAllocationCubemapFace)face);