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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/*
* Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Authors:
* Rob Clark <robclark@freedesktop.org>
*/
#include "pipe/p_state.h"
#include "pipe/p_screen.h"
#include "util/u_string.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
#include "util/format/u_format.h"
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_parse.h"
#include "nir/tgsi_to_nir.h"
#include "freedreno_context.h"
#include "freedreno_util.h"
#include "ir3/ir3_shader.h"
#include "ir3/ir3_gallium.h"
#include "ir3/ir3_compiler.h"
#include "ir3/ir3_nir.h"
static void
dump_shader_info(struct ir3_shader_variant *v, bool binning_pass,
struct pipe_debug_callback *debug)
{
if (!unlikely(fd_mesa_debug & FD_DBG_SHADERDB))
return;
pipe_debug_message(debug, SHADER_INFO,
"%s shader: %u inst, %u nops, %u non-nops, %u mov, %u cov, "
"%u dwords, %u last-baryf, %u half, %u full, %u constlen, "
"%u sstall, %u (ss), %u (sy), %d max_sun, %d loops\n",
ir3_shader_stage(v),
v->info.instrs_count,
v->info.nops_count,
v->info.instrs_count - v->info.nops_count,
v->info.mov_count,
v->info.cov_count,
v->info.sizedwords,
v->info.last_baryf,
v->info.max_half_reg + 1,
v->info.max_reg + 1,
v->constlen,
v->info.sstall,
v->info.ss, v->info.sy,
v->max_sun, v->loops);
}
struct ir3_shader_variant *
ir3_shader_variant(struct ir3_shader *shader, struct ir3_shader_key key,
bool binning_pass, struct pipe_debug_callback *debug)
{
struct ir3_shader_variant *v;
bool created = false;
/* some shader key values only apply to vertex or frag shader,
* so normalize the key to avoid constructing multiple identical
* variants:
*/
ir3_normalize_key(&key, shader->type);
v = ir3_shader_get_variant(shader, &key, binning_pass, &created);
if (created) {
dump_shader_info(v, binning_pass, debug);
}
return v;
}
static void
copy_stream_out(struct ir3_stream_output_info *i,
const struct pipe_stream_output_info *p)
{
STATIC_ASSERT(ARRAY_SIZE(i->stride) == ARRAY_SIZE(p->stride));
STATIC_ASSERT(ARRAY_SIZE(i->output) == ARRAY_SIZE(p->output));
i->num_outputs = p->num_outputs;
for (int n = 0; n < ARRAY_SIZE(i->stride); n++)
i->stride[n] = p->stride[n];
for (int n = 0; n < ARRAY_SIZE(i->output); n++) {
i->output[n].register_index = p->output[n].register_index;
i->output[n].start_component = p->output[n].start_component;
i->output[n].num_components = p->output[n].num_components;
i->output[n].output_buffer = p->output[n].output_buffer;
i->output[n].dst_offset = p->output[n].dst_offset;
i->output[n].stream = p->output[n].stream;
}
}
struct ir3_shader *
ir3_shader_create(struct ir3_compiler *compiler,
const struct pipe_shader_state *cso,
struct pipe_debug_callback *debug,
struct pipe_screen *screen)
{
nir_shader *nir;
if (cso->type == PIPE_SHADER_IR_NIR) {
/* we take ownership of the reference: */
nir = cso->ir.nir;
} else {
debug_assert(cso->type == PIPE_SHADER_IR_TGSI);
if (ir3_shader_debug & IR3_DBG_DISASM) {
tgsi_dump(cso->tokens, 0);
}
nir = tgsi_to_nir(cso->tokens, screen);
}
struct ir3_stream_output_info stream_output;
copy_stream_out(&stream_output, &cso->stream_output);
struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir, &stream_output);
if (fd_mesa_debug & FD_DBG_SHADERDB) {
/* if shader-db run, create a standard variant immediately
* (as otherwise nothing will trigger the shader to be
* actually compiled)
*/
static struct ir3_shader_key key; /* static is implicitly zeroed */
ir3_shader_variant(shader, key, false, debug);
if (nir->info.stage == MESA_SHADER_VERTEX)
ir3_shader_variant(shader, key, true, debug);
}
return shader;
}
/* a bit annoying that compute-shader and normal shader state objects
* aren't a bit more aligned.
*/
struct ir3_shader *
ir3_shader_create_compute(struct ir3_compiler *compiler,
const struct pipe_compute_state *cso,
struct pipe_debug_callback *debug,
struct pipe_screen *screen)
{
nir_shader *nir;
if (cso->ir_type == PIPE_SHADER_IR_NIR) {
/* we take ownership of the reference: */
nir = (nir_shader *)cso->prog;
} else {
debug_assert(cso->ir_type == PIPE_SHADER_IR_TGSI);
if (ir3_shader_debug & IR3_DBG_DISASM) {
tgsi_dump(cso->prog, 0);
}
nir = tgsi_to_nir(cso->prog, screen);
}
struct ir3_shader *shader = ir3_shader_from_nir(compiler, nir, NULL);
if (fd_mesa_debug & FD_DBG_SHADERDB) {
/* if shader-db run, create a standard variant immediately
* (as otherwise nothing will trigger the shader to be
* actually compiled)
*/
static struct ir3_shader_key key; /* static is implicitly zeroed */
ir3_shader_variant(shader, key, false, debug);
}
return shader;
}
static void *
ir3_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso)
{
struct fd_context *ctx = fd_context(pctx);
struct ir3_compiler *compiler = ctx->screen->compiler;
return ir3_shader_create(compiler, cso, &ctx->debug, pctx->screen);
}
static void
ir3_shader_state_delete(struct pipe_context *pctx, void *hwcso)
{
struct ir3_shader *so = hwcso;
ir3_shader_destroy(so);
}
void
ir3_prog_init(struct pipe_context *pctx)
{
pctx->create_vs_state = ir3_shader_state_create;
pctx->delete_vs_state = ir3_shader_state_delete;
pctx->create_tcs_state = ir3_shader_state_create;
pctx->delete_tcs_state = ir3_shader_state_delete;
pctx->create_tes_state = ir3_shader_state_create;
pctx->delete_tes_state = ir3_shader_state_delete;
pctx->create_gs_state = ir3_shader_state_create;
pctx->delete_gs_state = ir3_shader_state_delete;
pctx->create_fs_state = ir3_shader_state_create;
pctx->delete_fs_state = ir3_shader_state_delete;
}
|