rs_allocation.c revision a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12
15a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_core.rsh" 25a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_structs.h" 35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// Opaque Allocation type operations 55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) 65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsAllocationGetDimX(rs_allocation a) { 75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return alloc->mHal.drvState.lod[0].dimX; 95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) 125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsAllocationGetDimY(rs_allocation a) { 135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return alloc->mHal.drvState.lod[0].dimY; 155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) 185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsAllocationGetDimZ(rs_allocation a) { 195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return alloc->mHal.drvState.lod[0].dimZ; 215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) 245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsAllocationGetDimLOD(rs_allocation a) { 255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return alloc->mHal.state.hasMipmaps; 275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern uint32_t __attribute__((overloadable)) 305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsAllocationGetDimFaces(rs_allocation a) { 315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return alloc->mHal.state.hasFaces; 335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern rs_element __attribute__((overloadable)) 375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsAllocationGetElement(rs_allocation a) { 385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines if (alloc == NULL) { 405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rs_element nullElem = {0}; 415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return nullElem; 425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Type_t *type = (Type_t *)alloc->mHal.state.type; 445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rs_element returnElem = {type->mHal.state.element}; 455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return returnElem; 465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines// TODO: this needs to be optimized, obviously 495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesstatic void memcpy(void* dst, void* src, size_t size) { 505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines char* dst_c = (char*) dst, *src_c = (char*) src; 515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines for (; size > 0; size--) { 525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *dst_c++ = *src_c++; 535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#ifdef RS_DEBUG_RUNTIME 575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define ELEMENT_AT(T) \ 585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, const T *val, uint32_t x); \ 605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, const T *val, uint32_t x, uint32_t y); \ 625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, const T *val, uint32_t x, uint32_t y, uint32_t z); \ 645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, T *val, uint32_t x); \ 665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, T *val, uint32_t x, uint32_t y); \ 685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, T *val, uint32_t x, uint32_t y, uint32_t z); \ 705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, T val, uint32_t x) { \ 735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(a, &val, x); \ 745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y) { \ 775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(a, &val, x, y); \ 785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y, uint32_t z) { \ 815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(a, &val, x, y, z); \ 825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern T __attribute__((overloadable)) \ 845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, uint32_t x) { \ 855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T tmp; \ 865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(a, &tmp, x); \ 875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tmp; \ 885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern T __attribute__((overloadable)) \ 905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y) { \ 915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T tmp; \ 925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(a, &tmp, x, y); \ 935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tmp; \ 945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern T __attribute__((overloadable)) \ 965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { \ 975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T tmp; \ 985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(a, &tmp, x, y, z); \ 995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return tmp; \ 1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#else 10298f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser 1031ed5ef9b253850a199eecff6b7941e57c408e509Tobias Grosseruint8_t* 10498f1f05105146e1caeb124cae6e286c151f63151Tobias GrosserrsOffset(rs_allocation a, uint32_t sizeOf, uint32_t x, uint32_t y, 10598f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser uint32_t z) { 10698f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser Allocation_t *alloc = (Allocation_t *)a.p; 107a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams#ifdef __LP64__ 108a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams uint8_t *p = (uint8_t *)a.r; 109a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams#else 11098f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser uint8_t *p = (uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 111a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams#endif 112a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams const uint32_t stride = (uint32_t)alloc->mHal.drvState.lod[0].stride; 11398f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser const uint32_t dimY = alloc->mHal.drvState.lod[0].dimY; 11498f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser uint8_t *dp = &p[(sizeOf * x) + (y * stride) + 11598f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser (z * stride * dimY)]; 11698f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser return dp; 11798f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser} 11898f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser 11941660c4c73fc425a2e3511e2070b2748cdd1107cJason Samsuint8_t* 12041660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsrsOffsetNs(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { 12141660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams Allocation_t *alloc = (Allocation_t *)a.p; 122a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams#ifdef __LP64__ 123a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams uint8_t *p = (uint8_t *)a.r; 124a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams#else 12541660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams uint8_t *p = (uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 126a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams#endif 12741660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams const uint32_t stride = alloc->mHal.drvState.lod[0].stride; 12841660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams const uint32_t dimY = alloc->mHal.drvState.lod[0].dimY; 12941660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams const uint32_t sizeOf = alloc->mHal.state.elementSizeBytes;; 13041660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams uint8_t *dp = &p[(sizeOf * x) + (y * stride) + 13141660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams (z * stride * dimY)]; 13241660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams return dp; 13341660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams} 13441660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams 1355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define ELEMENT_AT(T) \ 13698f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1371ed5ef9b253850a199eecff6b7941e57c408e509Tobias Grosser void \ 13898f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsSetElementAtImpl_##T(rs_allocation a, T val, uint32_t x, \ 1391ed5ef9b253850a199eecff6b7941e57c408e509Tobias Grosser uint32_t y, uint32_t z); \ 14098f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 1425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt_##T(rs_allocation a, T val, uint32_t x) { \ 14398f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsSetElementAtImpl_##T(a, val, x, 0, 0); \ 1445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 14598f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 14798f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, \ 14898f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser uint32_t y) { \ 14998f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsSetElementAtImpl_##T(a, val, x, y, 0); \ 1505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 15198f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern void __attribute__((overloadable)) \ 15398f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y, \ 15498f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser uint32_t z) { \ 15598f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsSetElementAtImpl_##T(a, val, x, y, z); \ 15698f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser } \ 15798f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1581ed5ef9b253850a199eecff6b7941e57c408e509Tobias Grosser T \ 15998f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsGetElementAtImpl_##T(rs_allocation a, uint32_t x, uint32_t y, \ 1601ed5ef9b253850a199eecff6b7941e57c408e509Tobias Grosser uint32_t z); \ 16198f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern T __attribute__((overloadable)) \ 1635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, uint32_t x) { \ 16498f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser return rsGetElementAtImpl_##T(a, x, 0, 0); \ 1655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 16698f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern T __attribute__((overloadable)) \ 1685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y) { \ 16998f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser return rsGetElementAtImpl_##T(a, x, y, 0); \ 1705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } \ 17198f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser \ 1725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines extern T __attribute__((overloadable)) \ 17398f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, \ 17498f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser uint32_t z) { \ 17598f1f05105146e1caeb124cae6e286c151f63151Tobias Grosser return rsGetElementAtImpl_##T(a, x, y, z); \ 1765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines } 1775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern const void * __attribute__((overloadable)) 1815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt(rs_allocation a, uint32_t x) { 1825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 1835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 1845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t eSize = alloc->mHal.state.elementSizeBytes; 1855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return &p[eSize * x]; 1865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern const void * __attribute__((overloadable)) 1895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y) { 1905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 1915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 1925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t eSize = alloc->mHal.state.elementSizeBytes; 1935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t stride = alloc->mHal.drvState.lod[0].stride; 1945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return &p[(eSize * x) + (y * stride)]; 1955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 1965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern const void * __attribute__((overloadable)) 1985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { 1995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 2005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 2015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t eSize = alloc->mHal.state.elementSizeBytes; 2025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t stride = alloc->mHal.drvState.lod[0].stride; 2035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t dimY = alloc->mHal.drvState.lod[0].dimY; 2045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return &p[(eSize * x) + (y * stride) + (z * stride * dimY)]; 2055a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2065a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2075a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt(rs_allocation a, void* ptr, uint32_t x) { 2085a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 2095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 2105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t eSize = alloc->mHal.state.elementSizeBytes; 2115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines memcpy((void*)&p[eSize * x], ptr, eSize); 2125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt(rs_allocation a, void* ptr, uint32_t x, uint32_t y) { 2165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 2175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 2185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t eSize = alloc->mHal.state.elementSizeBytes; 2195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t stride = alloc->mHal.drvState.lod[0].stride; 2205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines memcpy((void*)&p[(eSize * x) + (y * stride)], ptr, eSize); 2215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern void __attribute__((overloadable)) 2245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsSetElementAt(rs_allocation a, void* ptr, uint32_t x, uint32_t y, uint32_t z) { 2255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 2265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.lod[0].mallocPtr; 2275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t eSize = alloc->mHal.state.elementSizeBytes; 2285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t stride = alloc->mHal.drvState.lod[0].stride; 2295a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines const uint32_t dimY = alloc->mHal.drvState.lod[0].dimY; 2305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines memcpy((void*)&p[(eSize * x) + (y * stride) + (z * stride * dimY)], ptr, eSize); 2315a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2325a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#endif 2335a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2345a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(char) 2355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(char2) 2365a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(char3) 2375a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(char4) 2385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uchar) 2395a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uchar2) 2405a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uchar3) 2415a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uchar4) 2425a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(short) 2435a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(short2) 2445a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(short3) 2455a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(short4) 2465a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ushort) 2475a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ushort2) 2485a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ushort3) 2495a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ushort4) 2505a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(int) 2515a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(int2) 2525a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(int3) 2535a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(int4) 2545a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uint) 2555a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uint2) 2565a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uint3) 2575a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(uint4) 2585a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(long) 2595a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(long2) 2605a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(long3) 2615a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(long4) 2625a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ulong) 2635a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ulong2) 2645a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ulong3) 2655a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(ulong4) 2665a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(float) 2675a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(float2) 2685a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(float3) 2695a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(float4) 2705a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(double) 2715a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(double2) 2725a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(double3) 2735a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesELEMENT_AT(double4) 2745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef ELEMENT_AT 2765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern const uchar __attribute__((overloadable)) 2795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAtYuv_uchar_Y(rs_allocation a, uint32_t x, uint32_t y) { 2805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return rsGetElementAt_uchar(a, x, y); 2815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern const uchar __attribute__((overloadable)) 2845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAtYuv_uchar_U(rs_allocation a, uint32_t x, uint32_t y) { 2855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 2875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 28861656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams const size_t cstep = alloc->mHal.drvState.yuv.step; 28961656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams const size_t shift = alloc->mHal.drvState.yuv.shift; 2900052f8dcb5ebb5c9205a1d25445629fb5a772380Jason Sams const size_t stride = alloc->mHal.drvState.lod[1].stride; 29161656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams 2920052f8dcb5ebb5c9205a1d25445629fb5a772380Jason Sams const uchar *pin = (const uchar *)alloc->mHal.drvState.lod[1].mallocPtr; 29361656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams 29461656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams return pin[((x >> shift) * cstep) + ((y >> shift) * stride)]; 2955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 2965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 2975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern const uchar __attribute__((overloadable)) 2985a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines rsGetElementAtYuv_uchar_V(rs_allocation a, uint32_t x, uint32_t y) { 2995a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 3005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines Allocation_t *alloc = (Allocation_t *)a.p; 3015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 30261656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams const size_t cstep = alloc->mHal.drvState.yuv.step; 30361656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams const size_t shift = alloc->mHal.drvState.yuv.shift; 3040052f8dcb5ebb5c9205a1d25445629fb5a772380Jason Sams const size_t stride = alloc->mHal.drvState.lod[2].stride; 30561656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams 3060052f8dcb5ebb5c9205a1d25445629fb5a772380Jason Sams const uchar *pin = (const uchar *)alloc->mHal.drvState.lod[2].mallocPtr; 30761656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams 30861656a7c6fc13421679d0a1cdf8b5b861e286892Jason Sams return pin[((x >> shift) * cstep) + ((y >> shift) * stride)]; 3095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 3105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 31141660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams 31241660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams#define VOP(T) \ 31341660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern void __rsAllocationVStoreXImpl_##T(rs_allocation a, const T val, uint32_t x, uint32_t y, uint32_t z); \ 31441660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern T __rsAllocationVLoadXImpl_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z); \ 31541660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams \ 31641660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern void __attribute__((overloadable)) \ 31741660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x) { \ 31841660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams __rsAllocationVStoreXImpl_##T(a, val, x, 0, 0); \ 31941660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams } \ 32041660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern void __attribute__((overloadable)) \ 32141660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x, uint32_t y) { \ 32241660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams __rsAllocationVStoreXImpl_##T(a, val, x, y, 0); \ 32341660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams } \ 32441660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern void __attribute__((overloadable)) \ 32541660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams rsAllocationVStoreX_##T(rs_allocation a, T val, uint32_t x, uint32_t y, uint32_t z) { \ 32641660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams __rsAllocationVStoreXImpl_##T(a, val, x, y, z); \ 32741660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams } \ 32841660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern T __attribute__((overloadable)) \ 32941660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams rsAllocationVLoadX_##T(rs_allocation a, uint32_t x) { \ 33041660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams return __rsAllocationVLoadXImpl_##T(a, x, 0, 0); \ 33141660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams } \ 33241660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern T __attribute__((overloadable)) \ 33341660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams rsAllocationVLoadX_##T(rs_allocation a, uint32_t x, uint32_t y) { \ 33441660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams return __rsAllocationVLoadXImpl_##T(a, x, y, 0); \ 33541660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams } \ 33641660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams extern T __attribute__((overloadable)) \ 33741660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams rsAllocationVLoadX_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { \ 33841660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams return __rsAllocationVLoadXImpl_##T(a, x, y, z); \ 33941660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams } 34041660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams 34141660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(char2) 34241660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(char3) 34341660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(char4) 34441660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(uchar2) 34541660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(uchar3) 34641660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(uchar4) 34741660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(short2) 34841660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(short3) 34941660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(short4) 35041660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(ushort2) 35141660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(ushort3) 35241660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(ushort4) 35341660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(int2) 35441660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(int3) 35541660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(int4) 35641660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(uint2) 35741660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(uint3) 35841660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(uint4) 35941660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(long2) 36041660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(long3) 36141660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(long4) 36241660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(ulong2) 36341660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(ulong3) 36441660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(ulong4) 36541660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(float2) 36641660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(float3) 36741660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(float4) 36841660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(double2) 36941660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(double3) 37041660c4c73fc425a2e3511e2070b2748cdd1107cJason SamsVOP(double4) 37141660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams 37241660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams#undef VOP 37341660c4c73fc425a2e3511e2070b2748cdd1107cJason Sams 374