Skip to content

Update definition of Buffer takes precedence over any prior usage #7514

@Carpetfizz

Description

@Carpetfizz

Consider this example where each pixel needs to undergo two tests. The final value of the pixel must be determined by the minimum value of the two tests.

Var x, y;
Func f;
int32_t width = 100;
int32_t height = 100;
Buffer<uint8_t> output(width, height);
Buffer<double> minBuffer(width, height);
minBuffer.fill(1e10);
f(x, y) = cast<uint8_t>(0);
std::vector<double> zs = {0, 1};
for (const double& z : zs)
{
    Expr zTest = Expr(z) < minBuffer(x, y);
    f(x, y) = select(zTest, cast<uint8_t>(Expr(z) * Expr(255)), f(x, y));
    minBuffer(x, y) = select(zTest, Expr(z), minBuffer(x, y));
}
f.realize(output);

In this case, the final value of the pixel must be 0 black image since the minimum z = 0. However, I'm getting back a white image, suggesting that the update definition to minBuffer is being evaluated before the zTest has taken place.

NOT A CONTRIBUTION

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions