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:
Matt Pharr
2011-11-30 13:17:31 -08:00
parent b48775a549
commit 8bc7367109
32 changed files with 1120 additions and 78 deletions

View File

@@ -61,14 +61,12 @@ mandelbrot_scanlines(uniform int ybase, uniform int span,
uniform int ystart = ybase + taskIndex * span;
uniform int yend = ystart + span;
for (uniform int j = ystart; j < yend; ++j) {
for (uniform int i = 0; i < width; i += programCount) {
float x = x0 + (programIndex + i) * dx;
float y = y0 + j * dy;
foreach (yi = ystart ... yend, xi = 0 ... width) {
float x = x0 + xi * dx;
float y = y0 + yi * dy;
int index = j * width + i + programIndex;
output[index] = mandel(x, y, maxIterations);
}
int index = yi * width + xi;
output[index] = mandel(x, y, maxIterations);
}
}