1# 2# Copyright (C) 2015 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 17header: 18summary: Kernel Invocation Functions and Types 19description: 20 The @rsForEach() function can be used to invoke the root kernel of a script. 21 22 The other functions are used to get the characteristics of the invocation of 23 an executing kernel, like dimensions and current indexes. These functions take 24 a @rs_kernel_context as argument. 25end: 26 27type: rs_for_each_strategy_t 28enum: rs_for_each_strategy 29value: RS_FOR_EACH_STRATEGY_SERIAL = 0, "Prefer contiguous memory regions." 30value: RS_FOR_EACH_STRATEGY_DONT_CARE = 1, "No prefrences." 31#TODO explain this better 32value: RS_FOR_EACH_STRATEGY_DST_LINEAR = 2, "Prefer DST." 33value: RS_FOR_EACH_STRATEGY_TILE_SMALL = 3, "Prefer processing small rectangular regions." 34value: RS_FOR_EACH_STRATEGY_TILE_MEDIUM = 4, "Prefer processing medium rectangular regions." 35value: RS_FOR_EACH_STRATEGY_TILE_LARGE = 5, "Prefer processing large rectangular regions." 36summary: Suggested cell processing order 37description: 38 This type is used to suggest how the invoked kernel should iterate over the cells of the 39 allocations. This is a hint only. Implementations may not follow the suggestion. 40 41 This specification can help the caching behavior of the running kernel, e.g. the cache 42 locality when the processing is distributed over multiple cores. 43end: 44 45type: rs_kernel_context 46version: 23 47simple: const struct rs_kernel_context_t * 48summary: Handle to a kernel invocation context 49description: 50 The kernel context contains common characteristics of the allocations being iterated 51 over, like dimensions, and rarely used indexes, like the Array0 index or the current 52 level of detail. 53 54 A kernel may be executed in parallel over multiple threads. Each thread will have its 55 own context. 56 57 You can access the context by adding a special parameter named "context" and of type 58 rs_kernel_context to your kernel function. See @rsGetDimX() and @rsGetArray0() for examples. 59end: 60 61type: rs_script_call_t 62struct: rs_script_call 63field: rs_for_each_strategy_t strategy, "Currently ignored. In the future, will be suggested cell iteration strategy." 64field: uint32_t xStart, "Starting index in the X dimension." 65field: uint32_t xEnd, "Ending index (exclusive) in the X dimension." 66field: uint32_t yStart, "Starting index in the Y dimension." 67field: uint32_t yEnd, "Ending index (exclusive) in the Y dimension." 68field: uint32_t zStart, "Starting index in the Z dimension." 69field: uint32_t zEnd, "Ending index (exclusive) in the Z dimension." 70field: uint32_t arrayStart, "Starting index in the Array0 dimension." 71field: uint32_t arrayEnd, "Ending index (exclusive) in the Array0 dimension." 72field: uint32_t array1Start, "Starting index in the Array1 dimension." 73field: uint32_t array1End, "Ending index (exclusive) in the Array1 dimension." 74field: uint32_t array2Start, "Starting index in the Array2 dimension." 75field: uint32_t array2End, "Ending index (exclusive) in the Array2 dimension." 76field: uint32_t array3Start, "Starting index in the Array3 dimension." 77field: uint32_t array3End, "Ending index (exclusive) in the Array3 dimension." 78summary: Cell iteration information 79description: 80 This structure is used to provide iteration information to a rsForEach call. 81 It is currently used to restrict processing to a subset of cells. In future 82 versions, it will also be used to provide hint on how to best iterate over 83 the cells. 84 85 The Start fields are inclusive and the End fields are exclusive. E.g. to iterate 86 over cells 4, 5, 6, and 7 in the X dimension, set xStart to 4 and xEnd to 8. 87end: 88 89function: rsForEach 90version: 9 13 91ret: void 92arg: rs_script script, "Script to call." 93arg: rs_allocation input, "Allocation to source data from." 94arg: rs_allocation output, "Allocation to write date into." 95arg: const void* usrData, "User defined data to pass to the script. May be NULL." 96arg: const rs_script_call_t* sc, "Extra control information used to select a sub-region of the allocation to be processed or suggest a walking strategy. May be NULL." 97summary: Invoke the root kernel of a script 98description: 99 Invoke the kernel named "root" of the specified script. Like other kernels, this root() 100 function will be invoked repeatedly over the cells of the specificed allocation, filling 101 the output allocation with the results. 102 103 When rsForEach is called, the root script is launched immediately. rsForEach returns 104 only when the script has completed and the output allocation is ready to use. 105 106 The rs_script argument is typically initialized using a global variable set from Java. 107 108 The kernel can be invoked with just an input allocation or just an output allocation. 109 This can be done by defining an rs_allocation variable and not initializing it. E.g.<code><br/> 110 rs_script gCustomScript;<br/> 111 void specializedProcessing(rs_allocation in) {<br/> 112 rs_allocation ignoredOut;<br/> 113 rsForEach(gCustomScript, in, ignoredOut);<br/> 114 }<br/></code> 115 116 If both input and output allocations are specified, they must have the same dimensions. 117test: none 118end: 119 120function: rsForEach 121version: 9 13 122ret: void 123arg: rs_script script 124arg: rs_allocation input 125arg: rs_allocation output 126arg: const void* usrData 127test: none 128end: 129 130function: rsForEach 131version: 14 20 132ret: void 133arg: rs_script script 134arg: rs_allocation input 135arg: rs_allocation output 136arg: const void* usrData 137arg: size_t usrDataLen, "Size of the userData structure. This will be used to perform a shallow copy of the data if necessary." 138arg: const rs_script_call_t* sc 139test: none 140end: 141 142function: rsForEach 143version: 14 20 144ret: void 145arg: rs_script script 146arg: rs_allocation input 147arg: rs_allocation output 148arg: const void* usrData 149arg: size_t usrDataLen 150test: none 151end: 152 153function: rsForEach 154version: 14 155ret: void 156arg: rs_script script 157arg: rs_allocation input 158arg: rs_allocation output 159test: none 160end: 161 162function: rsGetArray0 163version: 23 164ret: uint32_t 165arg: rs_kernel_context context 166summary: Index in the Array0 dimension for the specified context 167description: 168 Returns the index in the Array0 dimension of the cell being processed, as specified 169 by the supplied context. 170 171 This context is created when a kernel is launched and updated at each iteration. 172 It contains common characteristics of the allocations being iterated over and rarely 173 used indexes, like the Array0 index. 174 175 You can access the context by adding a special parameter named "context" and of 176 type rs_kernel_context to your kernel function. E.g.<br/> 177 <code>short RS_KERNEL myKernel(short value, uint32_t x, rs_kernel_context context) {<br/> 178 // The current index in the common x, y, z, w dimensions are accessed by<br/> 179 // adding these variables as arguments. For the more rarely used indexes<br/> 180 // to the other dimensions, extract them from the context:<br/> 181 uint32_t index_a0 = rsGetArray0(context);<br/> 182 //...<br/> 183 }<br/></code> 184 185 This function returns 0 if the Array0 dimension is not present. 186test: none 187end: 188 189function: rsGetArray1 190version: 23 191ret: uint32_t 192arg: rs_kernel_context context 193summary: Index in the Array1 dimension for the specified context 194description: 195 Returns the index in the Array1 dimension of the cell being processed, as specified 196 by the supplied context. See @rsGetArray0() for an explanation of the context. 197 198 Returns 0 if the Array1 dimension is not present. 199test: none 200end: 201 202function: rsGetArray2 203version: 23 204ret: uint32_t 205arg: rs_kernel_context context 206summary: Index in the Array2 dimension for the specified context 207description: 208 Returns the index in the Array2 dimension of the cell being processed, 209 as specified by the supplied context. See @rsGetArray0() for an explanation 210 of the context. 211 212 Returns 0 if the Array2 dimension is not present. 213test: none 214end: 215 216function: rsGetArray3 217version: 23 218ret: uint32_t 219arg: rs_kernel_context context 220summary: Index in the Array3 dimension for the specified context 221description: 222 Returns the index in the Array3 dimension of the cell being processed, as specified 223 by the supplied context. See @rsGetArray0() for an explanation of the context. 224 225 Returns 0 if the Array3 dimension is not present. 226test: none 227end: 228 229function: rsGetDimArray0 230version: 23 231ret: uint32_t 232arg: rs_kernel_context context 233summary: Size of the Array0 dimension for the specified context 234description: 235 Returns the size of the Array0 dimension for the specified context. 236 See @rsGetDimX() for an explanation of the context. 237 238 Returns 0 if the Array0 dimension is not present. 239#TODO Add an hyperlink to something that explains Array0/1/2/3 240# for the relevant functions. 241test: none 242end: 243 244function: rsGetDimArray1 245version: 23 246ret: uint32_t 247arg: rs_kernel_context context 248summary: Size of the Array1 dimension for the specified context 249description: 250 Returns the size of the Array1 dimension for the specified context. 251 See @rsGetDimX() for an explanation of the context. 252 253 Returns 0 if the Array1 dimension is not present. 254test: none 255end: 256 257function: rsGetDimArray2 258version: 23 259ret: uint32_t 260arg: rs_kernel_context context 261summary: Size of the Array2 dimension for the specified context 262description: 263 Returns the size of the Array2 dimension for the specified context. 264 See @rsGetDimX() for an explanation of the context. 265 266 Returns 0 if the Array2 dimension is not present. 267test: none 268end: 269 270function: rsGetDimArray3 271version: 23 272ret: uint32_t 273arg: rs_kernel_context context 274summary: Size of the Array3 dimension for the specified context 275description: 276 Returns the size of the Array3 dimension for the specified context. 277 See @rsGetDimX() for an explanation of the context. 278 279 Returns 0 if the Array3 dimension is not present. 280test: none 281end: 282 283function: rsGetDimHasFaces 284version: 23 285ret: bool, "Returns true if more than one face is present, false otherwise." 286arg: rs_kernel_context context 287summary: Presence of more than one face for the specified context 288description: 289 If the context refers to a cubemap, this function returns true if there's more than 290 one face present. In all other cases, it returns false. See @rsGetDimX() for an 291 explanation of the context. 292 293 @rsAllocationGetDimFaces() is similar but returns 0 or 1 instead of a bool. 294test: none 295end: 296 297function: rsGetDimLod 298version: 23 299ret: uint32_t 300arg: rs_kernel_context context 301summary: Number of levels of detail for the specified context 302description: 303 Returns the number of levels of detail for the specified context. This is useful 304 for mipmaps. See @rsGetDimX() for an explanation of the context. 305 306 Returns 0 if Level of Detail is not used. 307 308 @rsAllocationGetDimLOD() is similar but returns 0 or 1 instead the actual 309 number of levels. 310test: none 311end: 312 313function: rsGetDimX 314version: 23 315ret: uint32_t 316arg: rs_kernel_context context 317summary: Size of the X dimension for the specified context 318description: 319 Returns the size of the X dimension for the specified context. 320 321 This context is created when a kernel is launched. It contains common 322 characteristics of the allocations being iterated over by the kernel in 323 a very efficient structure. It also contains rarely used indexes. 324 325 You can access it by adding a special parameter named "context" and of 326 type rs_kernel_context to your kernel function. E.g.<br/> 327 <code>int4 RS_KERNEL myKernel(int4 value, rs_kernel_context context) {<br/> 328 uint32_t size = rsGetDimX(context); //...<br/></code> 329 330 To get the dimension of specific allocation, use @rsAllocationGetDimX(). 331test: none 332end: 333 334function: rsGetDimY 335version: 23 336ret: uint32_t 337arg: rs_kernel_context context 338summary: Size of the Y dimension for the specified context 339description: 340 Returns the size of the X dimension for the specified context. 341 See @rsGetDimX() for an explanation of the context. 342 343 Returns 0 if the Y dimension is not present. 344 345 To get the dimension of specific allocation, use @rsAllocationGetDimY(). 346test: none 347end: 348 349function: rsGetDimZ 350version: 23 351ret: uint32_t 352arg: rs_kernel_context context 353summary: Size of the Z dimension for the specified context 354description: 355 Returns the size of the Z dimension for the specified context. 356 See @rsGetDimX() for an explanation of the context. 357 358 Returns 0 if the Z dimension is not present. 359 360 To get the dimension of specific allocation, use @rsAllocationGetDimZ(). 361test: none 362end: 363 364function: rsGetFace 365version: 23 366ret: rs_allocation_cubemap_face 367arg: rs_kernel_context context 368summary: Coordinate of the Face for the specified context 369description: 370 Returns the face on which the cell being processed is found, as specified by the 371 supplied context. See @rsGetArray0() for an explanation of the context. 372 373 Returns RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X if the face dimension is not 374 present. 375test: none 376end: 377 378function: rsGetLod 379version: 23 380ret: uint32_t 381arg: rs_kernel_context context 382summary: Index in the Levels of Detail dimension for the specified context 383description: 384 Returns the index in the Levels of Detail dimension of the cell being processed, 385 as specified by the supplied context. See @rsGetArray0() for an explanation of 386 the context. 387 388 Returns 0 if the Levels of Detail dimension is not present. 389test: none 390end: 391