Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a5xx/fd5_draw.c
4574 views
1
/*
2
* Copyright (C) 2016 Rob Clark <[email protected]>
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 (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
* Authors:
24
* Rob Clark <[email protected]>
25
*/
26
27
#include "pipe/p_state.h"
28
#include "util/u_memory.h"
29
#include "util/u_prim.h"
30
#include "util/u_string.h"
31
32
#include "freedreno_resource.h"
33
#include "freedreno_state.h"
34
35
#include "fd5_context.h"
36
#include "fd5_draw.h"
37
#include "fd5_emit.h"
38
#include "fd5_format.h"
39
#include "fd5_program.h"
40
#include "fd5_zsa.h"
41
42
static void
43
draw_impl(struct fd_context *ctx, struct fd_ringbuffer *ring,
44
struct fd5_emit *emit, unsigned index_offset) assert_dt
45
{
46
const struct pipe_draw_info *info = emit->info;
47
enum pc_di_primtype primtype = ctx->primtypes[info->mode];
48
49
fd5_emit_state(ctx, ring, emit);
50
51
if (emit->dirty & (FD_DIRTY_VTXBUF | FD_DIRTY_VTXSTATE))
52
fd5_emit_vertex_bufs(ring, emit);
53
54
OUT_PKT4(ring, REG_A5XX_VFD_INDEX_OFFSET, 2);
55
OUT_RING(ring, info->index_size ? emit->draw->index_bias
56
: emit->draw->start); /* VFD_INDEX_OFFSET */
57
OUT_RING(ring, info->start_instance); /* VFD_INSTANCE_START_OFFSET */
58
59
OUT_PKT4(ring, REG_A5XX_PC_RESTART_INDEX, 1);
60
OUT_RING(ring, info->primitive_restart ? /* PC_RESTART_INDEX */
61
info->restart_index
62
: 0xffffffff);
63
64
fd5_emit_render_cntl(ctx, false, emit->binning_pass);
65
fd5_draw_emit(ctx->batch, ring, primtype,
66
emit->binning_pass ? IGNORE_VISIBILITY : USE_VISIBILITY, info,
67
emit->indirect, emit->draw, index_offset);
68
}
69
70
static bool
71
fd5_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,
72
unsigned drawid_offset,
73
const struct pipe_draw_indirect_info *indirect,
74
const struct pipe_draw_start_count_bias *draw,
75
unsigned index_offset) in_dt
76
{
77
struct fd5_context *fd5_ctx = fd5_context(ctx);
78
struct fd5_emit emit = {
79
.debug = &ctx->debug,
80
.vtx = &ctx->vtx,
81
.info = info,
82
.drawid_offset = drawid_offset,
83
.indirect = indirect,
84
.draw = draw,
85
.key = {
86
.vs = ctx->prog.vs,
87
.fs = ctx->prog.fs,
88
.key = {
89
.rasterflat = ctx->rasterizer->flatshade,
90
.has_per_samp = fd5_ctx->fastc_srgb || fd5_ctx->vastc_srgb,
91
.vastc_srgb = fd5_ctx->vastc_srgb,
92
.fastc_srgb = fd5_ctx->fastc_srgb,
93
},
94
},
95
.rasterflat = ctx->rasterizer->flatshade,
96
.sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,
97
.sprite_coord_mode = ctx->rasterizer->sprite_coord_mode,
98
};
99
100
ir3_fixup_shader_state(&ctx->base, &emit.key.key);
101
102
unsigned dirty = ctx->dirty;
103
104
emit.prog = fd5_program_state(
105
ir3_cache_lookup(ctx->shader_cache, &emit.key, &ctx->debug));
106
107
/* bail if compile failed: */
108
if (!emit.prog)
109
return false;
110
111
const struct ir3_shader_variant *vp = fd5_emit_get_vp(&emit);
112
const struct ir3_shader_variant *fp = fd5_emit_get_fp(&emit);
113
114
ir3_update_max_tf_vtx(ctx, vp);
115
116
/* do regular pass first: */
117
118
if (unlikely(ctx->stats_users > 0)) {
119
ctx->stats.vs_regs += ir3_shader_halfregs(vp);
120
ctx->stats.fs_regs += ir3_shader_halfregs(fp);
121
}
122
123
/* figure out whether we need to disable LRZ write for binning
124
* pass using draw pass's fp:
125
*/
126
emit.no_lrz_write = fp->writes_pos || fp->no_earlyz || fp->has_kill;
127
128
emit.binning_pass = false;
129
emit.dirty = dirty;
130
131
draw_impl(ctx, ctx->batch->draw, &emit, index_offset);
132
133
/* and now binning pass: */
134
emit.binning_pass = true;
135
emit.dirty = dirty & ~(FD_DIRTY_BLEND);
136
emit.vs = NULL; /* we changed key so need to refetch vp */
137
emit.fs = NULL;
138
draw_impl(ctx, ctx->batch->binning, &emit, index_offset);
139
140
if (emit.streamout_mask) {
141
struct fd_ringbuffer *ring = ctx->batch->draw;
142
143
for (unsigned i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
144
if (emit.streamout_mask & (1 << i)) {
145
fd5_event_write(ctx->batch, ring, FLUSH_SO_0 + i, false);
146
}
147
}
148
}
149
150
fd_context_all_clean(ctx);
151
152
return true;
153
}
154
155
static bool
156
is_z32(enum pipe_format format)
157
{
158
switch (format) {
159
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
160
case PIPE_FORMAT_Z32_UNORM:
161
case PIPE_FORMAT_Z32_FLOAT:
162
return true;
163
default:
164
return false;
165
}
166
}
167
168
static void
169
fd5_clear_lrz(struct fd_batch *batch, struct fd_resource *zsbuf, double depth)
170
{
171
struct fd_ringbuffer *ring;
172
uint32_t clear = util_pack_z(PIPE_FORMAT_Z16_UNORM, depth);
173
174
ring = fd_batch_get_prologue(batch);
175
176
OUT_WFI5(ring);
177
178
OUT_PKT4(ring, REG_A5XX_RB_CCU_CNTL, 1);
179
OUT_RING(ring, 0x10000000);
180
181
OUT_PKT4(ring, REG_A5XX_HLSQ_UPDATE_CNTL, 1);
182
OUT_RING(ring, 0x20fffff);
183
184
OUT_PKT4(ring, REG_A5XX_GRAS_SU_CNTL, 1);
185
OUT_RING(ring,
186
A5XX_GRAS_SU_CNTL_LINEHALFWIDTH(0.0) |
187
COND(zsbuf->b.b.nr_samples > 1, A5XX_GRAS_SU_CNTL_MSAA_ENABLE));
188
189
OUT_PKT4(ring, REG_A5XX_GRAS_CNTL, 1);
190
OUT_RING(ring, 0x00000000);
191
192
OUT_PKT4(ring, REG_A5XX_GRAS_CL_CNTL, 1);
193
OUT_RING(ring, 0x00000181);
194
195
OUT_PKT4(ring, REG_A5XX_GRAS_LRZ_CNTL, 1);
196
OUT_RING(ring, 0x00000000);
197
198
OUT_PKT4(ring, REG_A5XX_RB_MRT_BUF_INFO(0), 5);
199
OUT_RING(ring, A5XX_RB_MRT_BUF_INFO_COLOR_FORMAT(RB5_R16_UNORM) |
200
A5XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(TILE5_LINEAR) |
201
A5XX_RB_MRT_BUF_INFO_COLOR_SWAP(WZYX));
202
OUT_RING(ring, A5XX_RB_MRT_PITCH(zsbuf->lrz_pitch * 2));
203
OUT_RING(ring, A5XX_RB_MRT_ARRAY_PITCH(fd_bo_size(zsbuf->lrz)));
204
OUT_RELOC(ring, zsbuf->lrz, 0x1000, 0, 0);
205
206
OUT_PKT4(ring, REG_A5XX_RB_RENDER_CNTL, 1);
207
OUT_RING(ring, 0x00000000);
208
209
OUT_PKT4(ring, REG_A5XX_RB_DEST_MSAA_CNTL, 1);
210
OUT_RING(ring, A5XX_RB_DEST_MSAA_CNTL_SAMPLES(MSAA_ONE));
211
212
OUT_PKT4(ring, REG_A5XX_RB_BLIT_CNTL, 1);
213
OUT_RING(ring, A5XX_RB_BLIT_CNTL_BUF(BLIT_MRT0));
214
215
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_CNTL, 1);
216
OUT_RING(ring, A5XX_RB_CLEAR_CNTL_FAST_CLEAR | A5XX_RB_CLEAR_CNTL_MASK(0xf));
217
218
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_COLOR_DW0, 1);
219
OUT_RING(ring, clear); /* RB_CLEAR_COLOR_DW0 */
220
221
OUT_PKT4(ring, REG_A5XX_VSC_RESOLVE_CNTL, 2);
222
OUT_RING(ring, A5XX_VSC_RESOLVE_CNTL_X(zsbuf->lrz_width) |
223
A5XX_VSC_RESOLVE_CNTL_Y(zsbuf->lrz_height));
224
OUT_RING(ring, 0x00000000); // XXX UNKNOWN_0CDE
225
226
OUT_PKT4(ring, REG_A5XX_RB_CNTL, 1);
227
OUT_RING(ring, A5XX_RB_CNTL_BYPASS);
228
229
OUT_PKT4(ring, REG_A5XX_RB_RESOLVE_CNTL_1, 2);
230
OUT_RING(ring, A5XX_RB_RESOLVE_CNTL_1_X(0) | A5XX_RB_RESOLVE_CNTL_1_Y(0));
231
OUT_RING(ring, A5XX_RB_RESOLVE_CNTL_2_X(zsbuf->lrz_width - 1) |
232
A5XX_RB_RESOLVE_CNTL_2_Y(zsbuf->lrz_height - 1));
233
234
fd5_emit_blit(batch, ring);
235
}
236
237
static bool
238
fd5_clear(struct fd_context *ctx, unsigned buffers,
239
const union pipe_color_union *color, double depth,
240
unsigned stencil) assert_dt
241
{
242
struct fd_ringbuffer *ring = ctx->batch->draw;
243
struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
244
245
if ((buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) &&
246
is_z32(pfb->zsbuf->format))
247
return false;
248
249
fd5_emit_render_cntl(ctx, true, false);
250
251
if (buffers & PIPE_CLEAR_COLOR) {
252
for (int i = 0; i < pfb->nr_cbufs; i++) {
253
union util_color uc = {0};
254
255
if (!pfb->cbufs[i])
256
continue;
257
258
if (!(buffers & (PIPE_CLEAR_COLOR0 << i)))
259
continue;
260
261
enum pipe_format pfmt = pfb->cbufs[i]->format;
262
263
// XXX I think RB_CLEAR_COLOR_DWn wants to take into account SWAP??
264
union pipe_color_union swapped;
265
switch (fd5_pipe2swap(pfmt)) {
266
case WZYX:
267
swapped.ui[0] = color->ui[0];
268
swapped.ui[1] = color->ui[1];
269
swapped.ui[2] = color->ui[2];
270
swapped.ui[3] = color->ui[3];
271
break;
272
case WXYZ:
273
swapped.ui[2] = color->ui[0];
274
swapped.ui[1] = color->ui[1];
275
swapped.ui[0] = color->ui[2];
276
swapped.ui[3] = color->ui[3];
277
break;
278
case ZYXW:
279
swapped.ui[3] = color->ui[0];
280
swapped.ui[0] = color->ui[1];
281
swapped.ui[1] = color->ui[2];
282
swapped.ui[2] = color->ui[3];
283
break;
284
case XYZW:
285
swapped.ui[3] = color->ui[0];
286
swapped.ui[2] = color->ui[1];
287
swapped.ui[1] = color->ui[2];
288
swapped.ui[0] = color->ui[3];
289
break;
290
}
291
292
util_pack_color_union(pfmt, &uc, &swapped);
293
294
OUT_PKT4(ring, REG_A5XX_RB_BLIT_CNTL, 1);
295
OUT_RING(ring, A5XX_RB_BLIT_CNTL_BUF(BLIT_MRT0 + i));
296
297
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_CNTL, 1);
298
OUT_RING(ring,
299
A5XX_RB_CLEAR_CNTL_FAST_CLEAR | A5XX_RB_CLEAR_CNTL_MASK(0xf));
300
301
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_COLOR_DW0, 4);
302
OUT_RING(ring, uc.ui[0]); /* RB_CLEAR_COLOR_DW0 */
303
OUT_RING(ring, uc.ui[1]); /* RB_CLEAR_COLOR_DW1 */
304
OUT_RING(ring, uc.ui[2]); /* RB_CLEAR_COLOR_DW2 */
305
OUT_RING(ring, uc.ui[3]); /* RB_CLEAR_COLOR_DW3 */
306
307
fd5_emit_blit(ctx->batch, ring);
308
}
309
}
310
311
if (pfb->zsbuf && (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL))) {
312
uint32_t clear = util_pack_z_stencil(pfb->zsbuf->format, depth, stencil);
313
uint32_t mask = 0;
314
315
if (buffers & PIPE_CLEAR_DEPTH)
316
mask |= 0x1;
317
318
if (buffers & PIPE_CLEAR_STENCIL)
319
mask |= 0x2;
320
321
OUT_PKT4(ring, REG_A5XX_RB_BLIT_CNTL, 1);
322
OUT_RING(ring, A5XX_RB_BLIT_CNTL_BUF(BLIT_ZS));
323
324
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_CNTL, 1);
325
OUT_RING(ring,
326
A5XX_RB_CLEAR_CNTL_FAST_CLEAR | A5XX_RB_CLEAR_CNTL_MASK(mask));
327
328
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_COLOR_DW0, 1);
329
OUT_RING(ring, clear); /* RB_CLEAR_COLOR_DW0 */
330
331
fd5_emit_blit(ctx->batch, ring);
332
333
if (pfb->zsbuf && (buffers & PIPE_CLEAR_DEPTH)) {
334
struct fd_resource *zsbuf = fd_resource(pfb->zsbuf->texture);
335
if (zsbuf->lrz) {
336
zsbuf->lrz_valid = true;
337
fd5_clear_lrz(ctx->batch, zsbuf, depth);
338
}
339
}
340
}
341
342
/* disable fast clear to not interfere w/ gmem->mem, etc.. */
343
OUT_PKT4(ring, REG_A5XX_RB_CLEAR_CNTL, 1);
344
OUT_RING(ring, 0x00000000); /* RB_CLEAR_CNTL */
345
346
return true;
347
}
348
349
void
350
fd5_draw_init(struct pipe_context *pctx) disable_thread_safety_analysis
351
{
352
struct fd_context *ctx = fd_context(pctx);
353
ctx->draw_vbo = fd5_draw_vbo;
354
ctx->clear = fd5_clear;
355
}
356
357