Skip to content

Instantly share code, notes, and snippets.

@ronen
Created November 3, 2017 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronen/5887902d2da59edf64cdfd918e63cf74 to your computer and use it in GitHub Desktop.
Save ronen/5887902d2da59edf64cdfd918e63cf74 to your computer and use it in GitHub Desktop.
#include "Halide.h"
using namespace Halide;
Var x{"x"};
Var y{"y"};
Var c{"c"};
Buffer<float> input(100,100,3);
Buffer<float> dir(100);
Tuple step(const Func &f) {
Expr opx = f(x, y, c)[1];
Expr odx = f(x, y, c)[2];
Expr m = clamp(cast<int>(dir(opx)), -1, 1);
Expr dot = odx * m;
Expr dx = select(dot < 0, 0, m);
Expr dy = select(dot < 0, 0, 1);
Expr px = opx + dx;
Expr py = y + dy;
return Tuple(input(px, py, c), px, dx);
}
int main() {
const Target target = get_jit_target_from_environment().with_feature(Target::OpenGL);
Func f0("f0"), f1("f1"), f2("f2");
f0(x, y, c) = Tuple(0, x, y, dir(x, y, 0));
f1(x, y, c) = step(f0);
f2(x, y, c) = step(f1);
Func output("output");
output(x, y, c) = f1(x, y, c)[0] + f2(x, y, c)[0];
output.bound(c, 0, 3);
output.glsl(x, y, c);
output.realize(100, 100, 3, target); // Internal Error "Unknown intrinsic: glsl_texture_load"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment