<commit_before>#include "CodeGen_OpenGL_Dev.h"
#include "IRMatch.h"
#include "IRMutator.h"
#include "Debug.h"
#include "Simplify.h"

namespace Halide {
namespace Internal {

using std::ostringstream;
using std::string;
using std::vector;

static float max_value(const Type &type) {
    if (type == UInt(8)) {
        return 255.0f;
    } else if (type == UInt(16)) {
        return 65535.0f;
    } else {
        assert(false && "Cannot determine max_value of this type");
    }
    return 1.0f;
}


class InjectTextureLoads : public IRMutator {
public:
    using IRMutator::visit;

    void visit(const Cast *op) {
        const Load *load = op->value.as<Load>();
        if (load && op->type.is_float() && load->type.is_uint()) {
            assert(load->index.size() == 3 && "Load from texture requires multi-index");

            // Cast(float, Load(uint8,)) -> texture2D() * 255.f
            // Cast(float, Load(uint16,)) -> texture2D() * 65535.f
            vector<Expr> args(4);
            args[0] = load->name;
            args[1] = load->index[0];
            args[2] = load->index[1];
            args[3] = load->index[2];
            Expr new_load = Mul::make(
                Call::make(op->type, "glsl_texture_load",
                           args, Call::Intrinsic,
                           Function(), 0, load->image),
                max_value(load->type));
            new_load.accept(this);
        } else {
            IRMutator::visit(op);
        }
    }

    void visit(const Load *op) {
        assert(op->index.size() == 3 && "Load from texture requires multi-index");

        vector<Expr> args(4);
        args[0] = op->name;
        args[1] = op->index[0];
        args[2] = op->index[1];
        args[3] = op->index[2];
        Expr new_load =
            Cast::make(op->type,
                       Add::make(
                           Mul::make(
                               Call::make(Float(32), "glsl_texture_load",
                                          args, Call::Intrinsic,
                                          Function(), 0, op->image),
                               max_value(op->type)),
                           0.5f));<commit_msg>Remove rounding, truncation is always correct.<commit_after>#include "CodeGen_OpenGL_Dev.h"
#include "IRMatch.h"
#include "IRMutator.h"
#include "Debug.h"
#include "Simplify.h"

namespace Halide {
namespace Internal {

using std::ostringstream;
using std::string;
using std::vector;

static float max_value(const Type &type) {
    if (type == UInt(8)) {
        return 255.0f;
    } else if (type == UInt(16)) {
        return 65535.0f;
    } else {
        assert(false && "Cannot determine max_value of this type");
    }
    return 1.0f;
}


class InjectTextureLoads : public IRMutator {
public:
    using IRMutator::visit;

    void visit(const Cast *op) {
        const Load *load = op->value.as<Load>();
        if (load && op->type.is_float() && load->type.is_uint()) {
            assert(load->index.size() == 3 && "Load from texture requires multi-index");

            // Cast(float, Load(uint8,)) -> texture2D() * 255.f
            // Cast(float, Load(uint16,)) -> texture2D() * 65535.f
            vector<Expr> args(4);
            args[0] = load->name;
            args[1] = load->index[0];
            args[2] = load->index[1];
            args[3] = load->index[2];
            Expr new_load = Mul::make(
                Call::make(op->type, "glsl_texture_load",
                           args, Call::Intrinsic,
                           Function(), 0, load->image),
                max_value(load->type));
            new_load.accept(this);
        } else {
            IRMutator::visit(op);
        }
    }

    void visit(const Load *op) {
        assert(op->index.size() == 3 && "Load from texture requires multi-index");

        vector<Expr> args(4);
        args[0] = op->name;
        args[1] = op->index[0];
        args[2] = op->index[1];
        args[3] = op->index[2];
        Expr new_load =
            Cast::make(op->type,
                       Mul::make(
                           Call::make(Float(32), "glsl_texture_load",
                                      args, Call::Intrinsic,
                                      Function(), 0, op->image),
                           max_value(op->type))
                );
{'fraction_non_alphanumeric': 0.14983863531581373, 'fraction_numerical': 0.02351313969571231, 'mean_word_length': 1.670153846153846, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5752594', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1300, 'n_words': 282}