Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/frontends/clover/core/module.hpp
4572 views
1
//
2
// Copyright 2012 Francisco Jerez
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
// OTHER DEALINGS IN THE SOFTWARE.
21
//
22
23
#ifndef CLOVER_CORE_MODULE_HPP
24
#define CLOVER_CORE_MODULE_HPP
25
26
#include <vector>
27
#include <string>
28
29
#include "CL/cl.h"
30
31
namespace clover {
32
struct module {
33
typedef uint32_t resource_id;
34
typedef uint32_t size_t;
35
36
struct section {
37
enum type {
38
text_intermediate,
39
text_library,
40
text_executable,
41
data_constant,
42
data_global,
43
data_local,
44
data_private
45
};
46
47
section(resource_id id, enum type type, size_t size,
48
const std::vector<char> &data) :
49
id(id), type(type), size(size), data(data) { }
50
section() : id(0), type(text_intermediate), size(0), data() { }
51
52
resource_id id;
53
type type;
54
size_t size;
55
std::vector<char> data;
56
};
57
58
struct printf_info {
59
std::vector<uint32_t> arg_sizes;
60
std::vector<uint8_t> strings;
61
};
62
63
struct arg_info {
64
arg_info(const std::string &arg_name, const std::string &type_name,
65
const cl_kernel_arg_type_qualifier type_qualifier,
66
const cl_kernel_arg_address_qualifier address_qualifier,
67
const cl_kernel_arg_access_qualifier access_qualifier) :
68
arg_name(arg_name), type_name(type_name),
69
type_qualifier(type_qualifier),
70
address_qualifier(address_qualifier),
71
access_qualifier(access_qualifier) { };
72
arg_info() : arg_name(""), type_name(""), type_qualifier(0),
73
address_qualifier(0), access_qualifier(0) { };
74
75
std::string arg_name;
76
std::string type_name;
77
cl_kernel_arg_type_qualifier type_qualifier;
78
cl_kernel_arg_address_qualifier address_qualifier;
79
cl_kernel_arg_access_qualifier access_qualifier;
80
};
81
82
struct argument {
83
enum type {
84
scalar,
85
constant,
86
global,
87
local,
88
image_rd,
89
image_wr,
90
sampler
91
};
92
93
enum ext_type {
94
zero_ext,
95
sign_ext
96
};
97
98
enum semantic {
99
general,
100
grid_dimension,
101
grid_offset,
102
image_size,
103
image_format,
104
constant_buffer,
105
printf_buffer
106
};
107
108
argument(enum type type, size_t size,
109
size_t target_size, size_t target_align,
110
enum ext_type ext_type,
111
enum semantic semantic = general) :
112
type(type), size(size),
113
target_size(target_size), target_align(target_align),
114
ext_type(ext_type), semantic(semantic) { }
115
116
argument(enum type type, size_t size) :
117
type(type), size(size),
118
target_size(size), target_align(1),
119
ext_type(zero_ext), semantic(general) { }
120
121
argument() : type(scalar), size(0),
122
target_size(0), target_align(1),
123
ext_type(zero_ext), semantic(general) { }
124
125
type type;
126
size_t size;
127
size_t target_size;
128
size_t target_align;
129
ext_type ext_type;
130
semantic semantic;
131
arg_info info;
132
};
133
134
struct symbol {
135
symbol(const std::string &name, const std::string &attributes,
136
const std::vector<::size_t> &reqd_work_group_size,
137
resource_id section, size_t offset,
138
const std::vector<argument> &args) :
139
name(name), attributes(attributes),
140
reqd_work_group_size(reqd_work_group_size),
141
section(section),
142
offset(offset), args(args) { }
143
symbol() : name(), attributes(), reqd_work_group_size({0, 0, 0}),
144
section(0), offset(0), args() { }
145
146
std::string name;
147
std::string attributes;
148
std::vector<::size_t> reqd_work_group_size;
149
resource_id section;
150
size_t offset;
151
std::vector<argument> args;
152
};
153
154
module() : printf_strings_in_buffer(0) { }
155
void serialize(std::ostream &os) const;
156
static module deserialize(std::istream &is);
157
size_t size() const;
158
159
std::vector<symbol> syms;
160
std::vector<section> secs;
161
std::vector<printf_info> printf_infos;
162
// printfs strings stored in output buffer
163
uint32_t printf_strings_in_buffer;
164
};
165
}
166
167
#endif
168
169