forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeGen_OpenGL_Dev.h
More file actions
112 lines (79 loc) · 2.4 KB
/
CodeGen_OpenGL_Dev.h
File metadata and controls
112 lines (79 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef HALIDE_CODEGEN_OPENGL_DEV_H
#define HALIDE_CODEGEN_OPENGL_DEV_H
/** \file
* Defines the code-generator for producing GLSL kernel code
*/
#include <sstream>
#include <map>
#include "CodeGen_C.h"
#include "CodeGen_GPU_Dev.h"
#include "Target.h"
namespace Halide {
namespace Internal {
class CodeGen_GLSL;
class CodeGen_OpenGL_Dev : public CodeGen_GPU_Dev {
public:
CodeGen_OpenGL_Dev(const Target &target);
~CodeGen_OpenGL_Dev();
// CodeGen_GPU_Dev interface
void add_kernel(Stmt stmt, const std::string &name,
const std::vector<DeviceArgument> &args);
void init_module();
std::vector<char> compile_to_src();
std::string get_current_kernel_name();
void dump();
std::string api_unique_name() { return "opengl"; }
private:
CodeGen_GLSL *glc;
virtual std::string print_gpu_name(const std::string &name);
private:
std::ostringstream src_stream;
std::string cur_kernel_name;
Target target;
};
/**
* This class handles GLSL arithmetic, shared by CodeGen_GLSL and CodeGen_OpenGLCompute_C.
*/
class CodeGen_GLSLBase : public CodeGen_C {
public:
CodeGen_GLSLBase(std::ostream &s);
std::string print_name(const std::string &name);
std::string print_type(Type type, AppendSpaceIfNeeded space_option = DoNotAppendSpace);
protected:
using CodeGen_C::visit;
void visit(const Max *op);
void visit(const Min *op);
void visit(const Div *op);
void visit(const Mod *op);
void visit(const Call *op);
private:
std::map<std::string, std::string> builtin;
};
/** Compile one statement into GLSL. */
class CodeGen_GLSL : public CodeGen_GLSLBase {
public:
CodeGen_GLSL(std::ostream &s, const Target &target) : CodeGen_GLSLBase(s), target(target) {}
void add_kernel(Stmt stmt,
std::string name,
const std::vector<DeviceArgument> &args);
EXPORT static void test();
protected:
using CodeGen_C::visit;
void visit(const FloatImm *);
void visit(const Cast *);
void visit(const Let *);
void visit(const For *);
void visit(const Select *);
void visit(const Load *);
void visit(const Store *);
void visit(const Call *);
void visit(const AssertStmt *);
void visit(const Ramp *op);
void visit(const Broadcast *);
void visit(const Evaluate *);
private:
std::string get_vector_suffix(Expr e);
const Target target;
};
}}
#endif