Add foreach and foreach_tiled looping constructs
These make it easier to iterate over arbitrary amounts of data elements; specifically, they automatically handle the "ragged extra bits" that come up when the number of elements to be processed isn't evenly divided by programCount. TODO: documentation
This commit is contained in:
26
tests/foreach-2.ispc
Normal file
26
tests/foreach-2.ispc
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
|
||||
uniform int foo(int i);
|
||||
|
||||
export void f_f(uniform float RET[], uniform float aFOO[]) {
|
||||
uniform float val[programCount];
|
||||
for (uniform int i = 0; i < programCount; ++i)
|
||||
val[i] = 0;
|
||||
|
||||
foreach (i = 2 ... programCount)
|
||||
val[i] += i;
|
||||
|
||||
uniform float sum = 0;
|
||||
for (uniform int i = 0; i < programCount; ++i) {
|
||||
sum += val[i];
|
||||
}
|
||||
|
||||
RET[programIndex] = sum;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
int pi = (programIndex >= 2) ? programIndex : 0;
|
||||
RET[programIndex] = reduce_add(pi);
|
||||
}
|
||||
Reference in New Issue
Block a user