Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /** @file rs_allocation.rsh |
| 18 | * \brief Allocation routines |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef __RS_ALLOCATION_RSH__ |
| 24 | #define __RS_ALLOCATION_RSH__ |
| 25 | |
| 26 | /** |
| 27 | * Returns the Allocation for a given pointer. The pointer should point within |
| 28 | * a valid allocation. The results are undefined if the pointer is not from a |
| 29 | * valid allocation. |
Jason Sams | 08695a9 | 2012-09-20 18:30:21 -0700 | [diff] [blame] | 30 | * |
| 31 | * This function is deprecated and will be removed in the SDK from a future |
| 32 | * release. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 33 | */ |
| 34 | extern rs_allocation __attribute__((overloadable)) |
| 35 | rsGetAllocation(const void *); |
| 36 | |
| 37 | /** |
| 38 | * Query the dimension of an allocation. |
| 39 | * |
| 40 | * @return uint32_t The X dimension of the allocation. |
| 41 | */ |
| 42 | extern uint32_t __attribute__((overloadable)) |
| 43 | rsAllocationGetDimX(rs_allocation); |
| 44 | |
| 45 | /** |
| 46 | * Query the dimension of an allocation. |
| 47 | * |
| 48 | * @return uint32_t The Y dimension of the allocation. |
| 49 | */ |
| 50 | extern uint32_t __attribute__((overloadable)) |
| 51 | rsAllocationGetDimY(rs_allocation); |
| 52 | |
| 53 | /** |
| 54 | * Query the dimension of an allocation. |
| 55 | * |
| 56 | * @return uint32_t The Z dimension of the allocation. |
| 57 | */ |
| 58 | extern uint32_t __attribute__((overloadable)) |
| 59 | rsAllocationGetDimZ(rs_allocation); |
| 60 | |
| 61 | /** |
| 62 | * Query an allocation for the presence of more than one LOD. |
| 63 | * |
| 64 | * @return uint32_t Returns 1 if more than one LOD is present, 0 otherwise. |
| 65 | */ |
| 66 | extern uint32_t __attribute__((overloadable)) |
| 67 | rsAllocationGetDimLOD(rs_allocation); |
| 68 | |
| 69 | /** |
| 70 | * Query an allocation for the presence of more than one face. |
| 71 | * |
| 72 | * @return uint32_t Returns 1 if more than one face is present, 0 otherwise. |
| 73 | */ |
| 74 | extern uint32_t __attribute__((overloadable)) |
| 75 | rsAllocationGetDimFaces(rs_allocation); |
| 76 | |
Alex Sakhartchouk | 4325387 | 2011-09-28 15:23:18 -0700 | [diff] [blame] | 77 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 78 | |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Copy part of an allocation from another allocation. |
| 81 | * |
| 82 | * @param dstAlloc Allocation to copy data into. |
| 83 | * @param dstOff The offset of the first element to be copied in |
| 84 | * the destination allocation. |
| 85 | * @param dstMip Mip level in the destination allocation. |
| 86 | * @param count The number of elements to be copied. |
| 87 | * @param srcAlloc The source data allocation. |
| 88 | * @param srcOff The offset of the first element in data to be |
| 89 | * copied in the source allocation. |
| 90 | * @param srcMip Mip level in the source allocation. |
| 91 | */ |
| 92 | extern void __attribute__((overloadable)) |
| 93 | rsAllocationCopy1DRange(rs_allocation dstAlloc, |
| 94 | uint32_t dstOff, uint32_t dstMip, |
| 95 | uint32_t count, |
| 96 | rs_allocation srcAlloc, |
| 97 | uint32_t srcOff, uint32_t srcMip); |
| 98 | |
| 99 | /** |
| 100 | * Copy a rectangular region into the allocation from another |
| 101 | * allocation. |
| 102 | * |
| 103 | * @param dstAlloc allocation to copy data into. |
| 104 | * @param dstXoff X offset of the region to update in the |
| 105 | * destination allocation. |
| 106 | * @param dstYoff Y offset of the region to update in the |
| 107 | * destination allocation. |
| 108 | * @param dstMip Mip level in the destination allocation. |
| 109 | * @param dstFace Cubemap face of the destination allocation, |
| 110 | * ignored for allocations that aren't cubemaps. |
| 111 | * @param width Width of the incoming region to update. |
| 112 | * @param height Height of the incoming region to update. |
| 113 | * @param srcAlloc The source data allocation. |
| 114 | * @param srcXoff X offset in data of the source allocation. |
| 115 | * @param srcYoff Y offset in data of the source allocation. |
| 116 | * @param srcMip Mip level in the source allocation. |
| 117 | * @param srcFace Cubemap face of the source allocation, |
| 118 | * ignored for allocations that aren't cubemaps. |
| 119 | */ |
| 120 | extern void __attribute__((overloadable)) |
| 121 | rsAllocationCopy2DRange(rs_allocation dstAlloc, |
| 122 | uint32_t dstXoff, uint32_t dstYoff, |
| 123 | uint32_t dstMip, |
| 124 | rs_allocation_cubemap_face dstFace, |
| 125 | uint32_t width, uint32_t height, |
| 126 | rs_allocation srcAlloc, |
| 127 | uint32_t srcXoff, uint32_t srcYoff, |
| 128 | uint32_t srcMip, |
| 129 | rs_allocation_cubemap_face srcFace); |
| 130 | |
Alex Sakhartchouk | 4325387 | 2011-09-28 15:23:18 -0700 | [diff] [blame] | 131 | #endif //defined(RS_VERSION) && (RS_VERSION >= 14) |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * Extract a single element from an allocation. |
| 135 | */ |
| 136 | extern const void * __attribute__((overloadable)) |
| 137 | rsGetElementAt(rs_allocation, uint32_t x); |
| 138 | /** |
| 139 | * \overload |
| 140 | */ |
| 141 | extern const void * __attribute__((overloadable)) |
| 142 | rsGetElementAt(rs_allocation, uint32_t x, uint32_t y); |
| 143 | /** |
| 144 | * \overload |
| 145 | */ |
| 146 | extern const void * __attribute__((overloadable)) |
| 147 | rsGetElementAt(rs_allocation, uint32_t x, uint32_t y, uint32_t z); |
| 148 | |
Jason Sams | 9c7d4c4 | 2012-09-24 17:00:05 -0700 | [diff] [blame] | 149 | |
| 150 | #define GET_ELEMENT_AT(T) \ |
| 151 | static inline T __attribute__((overloadable)) \ |
| 152 | rsGetElementAt_##T(rs_allocation a, uint32_t x) { \ |
| 153 | return ((T *)rsGetElementAt(a, x))[0]; \ |
| 154 | } \ |
| 155 | static inline T __attribute__((overloadable)) \ |
| 156 | rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y) { \ |
| 157 | return ((T *)rsGetElementAt(a, x, y))[0]; \ |
| 158 | } \ |
| 159 | static inline T __attribute__((overloadable)) \ |
| 160 | rsGetElementAt_##T(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { \ |
| 161 | return ((T *)rsGetElementAt(a, x, y, z))[0]; \ |
| 162 | } |
| 163 | |
| 164 | GET_ELEMENT_AT(char) |
| 165 | GET_ELEMENT_AT(char2) |
| 166 | GET_ELEMENT_AT(char3) |
| 167 | GET_ELEMENT_AT(char4) |
| 168 | GET_ELEMENT_AT(uchar) |
| 169 | GET_ELEMENT_AT(uchar2) |
| 170 | GET_ELEMENT_AT(uchar3) |
| 171 | GET_ELEMENT_AT(uchar4) |
| 172 | GET_ELEMENT_AT(short) |
| 173 | GET_ELEMENT_AT(short2) |
| 174 | GET_ELEMENT_AT(short3) |
| 175 | GET_ELEMENT_AT(short4) |
| 176 | GET_ELEMENT_AT(ushort) |
| 177 | GET_ELEMENT_AT(ushort2) |
| 178 | GET_ELEMENT_AT(ushort3) |
| 179 | GET_ELEMENT_AT(ushort4) |
| 180 | GET_ELEMENT_AT(int) |
| 181 | GET_ELEMENT_AT(int2) |
| 182 | GET_ELEMENT_AT(int3) |
| 183 | GET_ELEMENT_AT(int4) |
| 184 | GET_ELEMENT_AT(uint) |
| 185 | GET_ELEMENT_AT(uint2) |
| 186 | GET_ELEMENT_AT(uint3) |
| 187 | GET_ELEMENT_AT(uint4) |
| 188 | GET_ELEMENT_AT(long) |
| 189 | GET_ELEMENT_AT(long2) |
| 190 | GET_ELEMENT_AT(long3) |
| 191 | GET_ELEMENT_AT(long4) |
| 192 | GET_ELEMENT_AT(ulong) |
| 193 | GET_ELEMENT_AT(ulong2) |
| 194 | GET_ELEMENT_AT(ulong3) |
| 195 | GET_ELEMENT_AT(ulong4) |
| 196 | GET_ELEMENT_AT(float) |
| 197 | GET_ELEMENT_AT(float2) |
| 198 | GET_ELEMENT_AT(float3) |
| 199 | GET_ELEMENT_AT(float4) |
| 200 | GET_ELEMENT_AT(double) |
| 201 | GET_ELEMENT_AT(double2) |
| 202 | GET_ELEMENT_AT(double3) |
| 203 | GET_ELEMENT_AT(double4) |
| 204 | |
| 205 | #undef GET_ELEMENT_AT |
| 206 | |
Tim Murray | cc63efe | 2012-10-17 11:43:50 -0700 | [diff] [blame] | 207 | // Jelly Bean |
Alex Sakhartchouk | 3c0c606 | 2012-03-22 16:59:38 -0700 | [diff] [blame] | 208 | #if (defined(RS_VERSION) && (RS_VERSION >= 16)) |
| 209 | |
Alex Sakhartchouk | 8d0f59e | 2011-12-16 14:15:07 -0800 | [diff] [blame] | 210 | /** |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 211 | * Send the contents of the Allocation to the queue. |
Alex Sakhartchouk | 340d15a | 2012-04-16 13:50:40 -0700 | [diff] [blame] | 212 | * @param a allocation to work on |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 213 | */ |
| 214 | extern const void __attribute__((overloadable)) |
Alex Sakhartchouk | 340d15a | 2012-04-16 13:50:40 -0700 | [diff] [blame] | 215 | rsAllocationIoSend(rs_allocation a); |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Receive a new set of contents from the queue. |
Alex Sakhartchouk | 340d15a | 2012-04-16 13:50:40 -0700 | [diff] [blame] | 219 | * @param a allocation to work on |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 220 | */ |
| 221 | extern const void __attribute__((overloadable)) |
Alex Sakhartchouk | 340d15a | 2012-04-16 13:50:40 -0700 | [diff] [blame] | 222 | rsAllocationIoReceive(rs_allocation a); |
Jason Sams | b322033 | 2012-04-02 14:41:54 -0700 | [diff] [blame] | 223 | |
| 224 | |
| 225 | /** |
Alex Sakhartchouk | 340d15a | 2012-04-16 13:50:40 -0700 | [diff] [blame] | 226 | * Get the element object describing the allocation's layout |
Alex Sakhartchouk | 8d0f59e | 2011-12-16 14:15:07 -0800 | [diff] [blame] | 227 | * @param a allocation to get data from |
| 228 | * @return element describing allocation layout |
| 229 | */ |
Alex Sakhartchouk | b0fa3a6 | 2011-12-16 09:44:26 -0800 | [diff] [blame] | 230 | extern rs_element __attribute__((overloadable)) |
Alex Sakhartchouk | 8d0f59e | 2011-12-16 14:15:07 -0800 | [diff] [blame] | 231 | rsAllocationGetElement(rs_allocation a); |
Alex Sakhartchouk | 253325d | 2011-12-15 09:56:10 -0800 | [diff] [blame] | 232 | |
Alex Sakhartchouk | 8d0f59e | 2011-12-16 14:15:07 -0800 | [diff] [blame] | 233 | /** |
Alex Sakhartchouk | 09db907 | 2012-02-29 16:43:24 -0800 | [diff] [blame] | 234 | * Fetch allocation in a way described by the sampler |
| 235 | * @param a 1D allocation to sample from |
| 236 | * @param s sampler state |
| 237 | * @param location to sample from |
| 238 | */ |
| 239 | extern const float4 __attribute__((overloadable)) |
| 240 | rsSample(rs_allocation a, rs_sampler s, float location); |
| 241 | /** |
| 242 | * Fetch allocation in a way described by the sampler |
| 243 | * @param a 1D allocation to sample from |
| 244 | * @param s sampler state |
| 245 | * @param location to sample from |
| 246 | * @param lod mip level to sample from, for fractional values |
| 247 | * mip levels will be interpolated if |
| 248 | * RS_SAMPLER_LINEAR_MIP_LINEAR is used |
| 249 | */ |
| 250 | extern const float4 __attribute__((overloadable)) |
| 251 | rsSample(rs_allocation a, rs_sampler s, float location, float lod); |
| 252 | |
| 253 | /** |
| 254 | * Fetch allocation in a way described by the sampler |
| 255 | * @param a 2D allocation to sample from |
| 256 | * @param s sampler state |
| 257 | * @param location to sample from |
| 258 | */ |
| 259 | extern const float4 __attribute__((overloadable)) |
| 260 | rsSample(rs_allocation a, rs_sampler s, float2 location); |
| 261 | |
| 262 | /** |
| 263 | * Fetch allocation in a way described by the sampler |
| 264 | * @param a 2D allocation to sample from |
| 265 | * @param s sampler state |
| 266 | * @param location to sample from |
| 267 | * @param lod mip level to sample from, for fractional values |
| 268 | * mip levels will be interpolated if |
| 269 | * RS_SAMPLER_LINEAR_MIP_LINEAR is used |
| 270 | */ |
| 271 | extern const float4 __attribute__((overloadable)) |
| 272 | rsSample(rs_allocation a, rs_sampler s, float2 location, float lod); |
| 273 | |
Alex Sakhartchouk | 3c0c606 | 2012-03-22 16:59:38 -0700 | [diff] [blame] | 274 | #endif // (defined(RS_VERSION) && (RS_VERSION >= 16)) |
Alex Sakhartchouk | 09db907 | 2012-02-29 16:43:24 -0800 | [diff] [blame] | 275 | |
Tim Murray | cc63efe | 2012-10-17 11:43:50 -0700 | [diff] [blame] | 276 | #if (defined(RS_VERSION) && (RS_VERSION >= 18)) |
| 277 | |
| 278 | /** |
| 279 | * Set single element of an allocation. |
| 280 | */ |
| 281 | extern void __attribute__((overloadable)) |
| 282 | rsSetElementAt(rs_allocation a, void* ptr, uint32_t x); |
| 283 | |
| 284 | /** |
| 285 | * \overload |
| 286 | */ |
| 287 | extern void __attribute__((overloadable)) |
| 288 | rsSetElementAt(rs_allocation a, void* ptr, uint32_t x, uint32_t y); |
Tim Murray | 1a56976 | 2012-12-11 15:25:12 -0800 | [diff] [blame] | 289 | |
| 290 | #define SET_ELEMENT_AT(T) \ |
| 291 | extern void __attribute__((overloadable)) \ |
| 292 | __rsSetElementAt_##T(rs_allocation a, T val, uint32_t x); \ |
| 293 | extern void __attribute__((overloadable)) \ |
| 294 | __rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y); \ |
| 295 | \ |
| 296 | static inline void __attribute__((overloadable)) \ |
| 297 | rsSetElementAt_##T(rs_allocation a, T val, uint32_t x) { \ |
| 298 | __rsSetElementAt_##T(a, val, x); \ |
| 299 | } \ |
| 300 | static inline void __attribute__((overloadable)) \ |
| 301 | rsSetElementAt_##T(rs_allocation a, T val, uint32_t x, uint32_t y) { \ |
| 302 | __rsSetElementAt_##T(a, val, x, y); \ |
| 303 | } \ |
| 304 | |
| 305 | SET_ELEMENT_AT(char) |
| 306 | SET_ELEMENT_AT(char2) |
| 307 | SET_ELEMENT_AT(char3) |
| 308 | SET_ELEMENT_AT(char4) |
| 309 | SET_ELEMENT_AT(uchar) |
| 310 | SET_ELEMENT_AT(uchar2) |
| 311 | SET_ELEMENT_AT(uchar3) |
| 312 | SET_ELEMENT_AT(uchar4) |
| 313 | SET_ELEMENT_AT(short) |
| 314 | SET_ELEMENT_AT(short2) |
| 315 | SET_ELEMENT_AT(short3) |
| 316 | SET_ELEMENT_AT(short4) |
| 317 | SET_ELEMENT_AT(ushort) |
| 318 | SET_ELEMENT_AT(ushort2) |
| 319 | SET_ELEMENT_AT(ushort3) |
| 320 | SET_ELEMENT_AT(ushort4) |
| 321 | SET_ELEMENT_AT(int) |
| 322 | SET_ELEMENT_AT(int2) |
| 323 | SET_ELEMENT_AT(int3) |
| 324 | SET_ELEMENT_AT(int4) |
| 325 | SET_ELEMENT_AT(uint) |
| 326 | SET_ELEMENT_AT(uint2) |
| 327 | SET_ELEMENT_AT(uint3) |
| 328 | SET_ELEMENT_AT(uint4) |
| 329 | SET_ELEMENT_AT(long) |
| 330 | SET_ELEMENT_AT(long2) |
| 331 | SET_ELEMENT_AT(long3) |
| 332 | SET_ELEMENT_AT(long4) |
| 333 | SET_ELEMENT_AT(ulong) |
| 334 | SET_ELEMENT_AT(ulong2) |
| 335 | SET_ELEMENT_AT(ulong3) |
| 336 | SET_ELEMENT_AT(ulong4) |
| 337 | SET_ELEMENT_AT(float) |
| 338 | SET_ELEMENT_AT(float2) |
| 339 | SET_ELEMENT_AT(float3) |
| 340 | SET_ELEMENT_AT(float4) |
| 341 | SET_ELEMENT_AT(double) |
| 342 | SET_ELEMENT_AT(double2) |
| 343 | SET_ELEMENT_AT(double3) |
| 344 | SET_ELEMENT_AT(double4) |
| 345 | |
| 346 | #undef SET_ELEMENT_AT |
| 347 | |
| 348 | |
Tim Murray | cc63efe | 2012-10-17 11:43:50 -0700 | [diff] [blame] | 349 | #endif // (defined(RS_VERSION) && (RS_VERSION >= 18)) |
| 350 | |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 351 | #endif |
| 352 | |