1

I am trying to re-implement the bilateral grid example with multi-channel input/output(3 channels image). And try to use the OpenGL/GLSL schedule. Here is the code segments that I wrote.

class BilateralGrid : public Halide::Generator<BilateralGrid> {
public:
GeneratorParam<int>   s_sigma{"s_sigma", 8};

ImageParam            input{Float(32), 3, "input"};
Param<float>          r_sigma{"r_sigma"};

Func build() {
    Var x("x"), y("y"), z("z"), c("c"), ch("ch");

     ...         

    Func histogram("histogram");
    histogram(x, y, ch, z, c) = 0.0f;
    histogram(x, y, ch, zi, c) += select(c == 0, val, 1.0f);

    ...

    input.dim(2).set_bounds(0,3);
    bilateral_grid.bound(ch, 0 ,3);
    bilateral_grid.glsl(x , y, ch);

    return bilateral_grid;
    }
};

Halide::RegisterGenerator<BilateralGrid> register_me{"bilateral_grid"};

But I've got an error when trying to compile the code.

Error
Allocations inside GLSL kernels must be constant-sized

In my limited experience with halide, I can't find why...

Thanks in advance.

4
  • How is histogram scheduled? Seems unlikely a histogram reduction is going to work in GLSL. May 8, 2017 at 23:00
  • There is no explicit schedule for histogram. Indeed, I also noticed the halide mentioned that "This covers a wide range of interesting operations like point-wise filters and convolutions; but a few common image processing operations such as histograms or recursive filters are notoriously hard to express in GLSL." But , I want to know why, or have the opportunity to improve it?
    – bourne
    May 9, 2017 at 2:17
  • Strict fragment shaders can read from multiple inputs, but can only write to the output at the pixel location where they are invoked. That is they have gather capability, often somewhat limited, but no scatter. Implementing a histogram in the normal fashion is not possible under these constraints. Alternative approaches, tend to fall into the realm of puzzle solving gimmicks rather than useful machinery. shaderwrangler.com/publications/histogram/… presents one approach but it uses vertex shaders. Usually a more powerful GPU API is a better bet. May 9, 2017 at 3:19
  • @ZalmanStern, thank you for your answer sincerely. I am also looking forward that halide can express histogram with GLSL more smoothly in the future.....
    – bourne
    May 9, 2017 at 6:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.