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:
23
tests/foreach-8.ispc
Normal file
23
tests/foreach-8.ispc
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
export void f_f(uniform float RET[], uniform float aFOO[]) {
|
||||
float sum1 = 0, sum2 = 0;
|
||||
foreach (x = 0 ... 10, i = 0 ... 6) {
|
||||
sum1 += aFOO[i];
|
||||
}
|
||||
|
||||
for (uniform int x = 0; x < 10; ++x) {
|
||||
for (uniform int i = 0; i < 6; i += programCount) {
|
||||
int index = i + programIndex;
|
||||
if (index < 6)
|
||||
sum2 += aFOO[index];
|
||||
}
|
||||
}
|
||||
|
||||
RET[programIndex] = sum1 - sum2;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user