Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
4574 views
1
/*
2
* Copyright (C) 2016 Rob Clark <[email protected]>
3
* Copyright © 2018 Google, Inc.
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
14
* Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* SOFTWARE.
23
*
24
* Authors:
25
* Rob Clark <[email protected]>
26
*/
27
28
#include "pipe/p_state.h"
29
#include "util/format/u_format.h"
30
#include "util/u_helpers.h"
31
#include "util/u_memory.h"
32
#include "util/u_string.h"
33
#include "util/u_viewport.h"
34
35
#include "common/freedreno_guardband.h"
36
#include "freedreno_query_hw.h"
37
#include "freedreno_resource.h"
38
#include "freedreno_state.h"
39
#include "freedreno_tracepoints.h"
40
41
#include "fd6_blend.h"
42
#include "fd6_const.h"
43
#include "fd6_context.h"
44
#include "fd6_emit.h"
45
#include "fd6_format.h"
46
#include "fd6_image.h"
47
#include "fd6_pack.h"
48
#include "fd6_program.h"
49
#include "fd6_rasterizer.h"
50
#include "fd6_texture.h"
51
#include "fd6_zsa.h"
52
53
/* Border color layout is diff from a4xx/a5xx.. if it turns out to be
54
* the same as a6xx then move this somewhere common ;-)
55
*
56
* Entry layout looks like (total size, 0x60 bytes):
57
*/
58
59
struct PACKED bcolor_entry {
60
uint32_t fp32[4];
61
uint16_t ui16[4];
62
int16_t si16[4];
63
uint16_t fp16[4];
64
uint16_t rgb565;
65
uint16_t rgb5a1;
66
uint16_t rgba4;
67
uint8_t __pad0[2];
68
uint8_t ui8[4];
69
int8_t si8[4];
70
uint32_t rgb10a2;
71
uint32_t z24; /* also s8? */
72
uint16_t
73
srgb[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
74
uint8_t __pad1[56];
75
};
76
77
#define FD6_BORDER_COLOR_SIZE sizeof(struct bcolor_entry)
78
#define FD6_BORDER_COLOR_UPLOAD_SIZE \
79
(2 * PIPE_MAX_SAMPLERS * FD6_BORDER_COLOR_SIZE)
80
81
static void
82
setup_border_colors(struct fd_texture_stateobj *tex,
83
struct bcolor_entry *entries)
84
{
85
unsigned i, j;
86
STATIC_ASSERT(sizeof(struct bcolor_entry) == FD6_BORDER_COLOR_SIZE);
87
88
for (i = 0; i < tex->num_samplers; i++) {
89
struct bcolor_entry *e = &entries[i];
90
struct pipe_sampler_state *sampler = tex->samplers[i];
91
union pipe_color_union *bc;
92
93
if (!sampler)
94
continue;
95
96
bc = &sampler->border_color;
97
98
/*
99
* XXX HACK ALERT XXX
100
*
101
* The border colors need to be swizzled in a particular
102
* format-dependent order. Even though samplers don't know about
103
* formats, we can assume that with a GL state tracker, there's a
104
* 1:1 correspondence between sampler and texture. Take advantage
105
* of that knowledge.
106
*/
107
if ((i >= tex->num_textures) || !tex->textures[i])
108
continue;
109
110
struct pipe_sampler_view *view = tex->textures[i];
111
enum pipe_format format = view->format;
112
const struct util_format_description *desc =
113
util_format_description(format);
114
115
e->rgb565 = 0;
116
e->rgb5a1 = 0;
117
e->rgba4 = 0;
118
e->rgb10a2 = 0;
119
e->z24 = 0;
120
121
unsigned char swiz[4];
122
123
fd6_tex_swiz(format, swiz, view->swizzle_r, view->swizzle_g,
124
view->swizzle_b, view->swizzle_a);
125
126
for (j = 0; j < 4; j++) {
127
int c = swiz[j];
128
int cd = c;
129
130
/*
131
* HACK: for PIPE_FORMAT_X24S8_UINT we end up w/ the
132
* stencil border color value in bc->ui[0] but according
133
* to desc->swizzle and desc->channel, the .x/.w component
134
* is NONE and the stencil value is in the y component.
135
* Meanwhile the hardware wants this in the .w component
136
* for x24s8 and the .x component for x32_s8x24.
137
*/
138
if ((format == PIPE_FORMAT_X24S8_UINT) ||
139
(format == PIPE_FORMAT_X32_S8X24_UINT)) {
140
if (j == 0) {
141
c = 1;
142
cd = (format == PIPE_FORMAT_X32_S8X24_UINT) ? 0 : 3;
143
} else {
144
continue;
145
}
146
}
147
148
if (c >= 4)
149
continue;
150
151
if (desc->channel[c].pure_integer) {
152
uint16_t clamped;
153
switch (desc->channel[c].size) {
154
case 2:
155
assert(desc->channel[c].type == UTIL_FORMAT_TYPE_UNSIGNED);
156
clamped = CLAMP(bc->ui[j], 0, 0x3);
157
break;
158
case 8:
159
if (desc->channel[c].type == UTIL_FORMAT_TYPE_SIGNED)
160
clamped = CLAMP(bc->i[j], -128, 127);
161
else
162
clamped = CLAMP(bc->ui[j], 0, 255);
163
break;
164
case 10:
165
assert(desc->channel[c].type == UTIL_FORMAT_TYPE_UNSIGNED);
166
clamped = CLAMP(bc->ui[j], 0, 0x3ff);
167
break;
168
case 16:
169
if (desc->channel[c].type == UTIL_FORMAT_TYPE_SIGNED)
170
clamped = CLAMP(bc->i[j], -32768, 32767);
171
else
172
clamped = CLAMP(bc->ui[j], 0, 65535);
173
break;
174
default:
175
assert(!"Unexpected bit size");
176
case 32:
177
clamped = 0;
178
break;
179
}
180
e->fp32[cd] = bc->ui[j];
181
e->fp16[cd] = clamped;
182
} else {
183
float f = bc->f[j];
184
float f_u = CLAMP(f, 0, 1);
185
float f_s = CLAMP(f, -1, 1);
186
187
e->fp32[c] = fui(f);
188
e->fp16[c] = _mesa_float_to_half(f);
189
e->srgb[c] = _mesa_float_to_half(f_u);
190
e->ui16[c] = f_u * 0xffff;
191
e->si16[c] = f_s * 0x7fff;
192
e->ui8[c] = f_u * 0xff;
193
e->si8[c] = f_s * 0x7f;
194
if (c == 1)
195
e->rgb565 |= (int)(f_u * 0x3f) << 5;
196
else if (c < 3)
197
e->rgb565 |= (int)(f_u * 0x1f) << (c ? 11 : 0);
198
if (c == 3)
199
e->rgb5a1 |= (f_u > 0.5) ? 0x8000 : 0;
200
else
201
e->rgb5a1 |= (int)(f_u * 0x1f) << (c * 5);
202
if (c == 3)
203
e->rgb10a2 |= (int)(f_u * 0x3) << 30;
204
else
205
e->rgb10a2 |= (int)(f_u * 0x3ff) << (c * 10);
206
e->rgba4 |= (int)(f_u * 0xf) << (c * 4);
207
if (c == 0)
208
e->z24 = f_u * 0xffffff;
209
}
210
}
211
212
#ifdef DEBUG
213
memset(&e->__pad0, 0, sizeof(e->__pad0));
214
memset(&e->__pad1, 0, sizeof(e->__pad1));
215
#endif
216
}
217
}
218
219
static void
220
emit_border_color(struct fd_context *ctx, struct fd_ringbuffer *ring) assert_dt
221
{
222
struct fd6_context *fd6_ctx = fd6_context(ctx);
223
struct bcolor_entry *entries;
224
unsigned off;
225
void *ptr;
226
227
STATIC_ASSERT(sizeof(struct bcolor_entry) == FD6_BORDER_COLOR_SIZE);
228
229
u_upload_alloc(fd6_ctx->border_color_uploader, 0,
230
FD6_BORDER_COLOR_UPLOAD_SIZE, FD6_BORDER_COLOR_UPLOAD_SIZE,
231
&off, &fd6_ctx->border_color_buf, &ptr);
232
233
entries = ptr;
234
235
setup_border_colors(&ctx->tex[PIPE_SHADER_VERTEX], &entries[0]);
236
setup_border_colors(&ctx->tex[PIPE_SHADER_FRAGMENT],
237
&entries[ctx->tex[PIPE_SHADER_VERTEX].num_samplers]);
238
239
OUT_PKT4(ring, REG_A6XX_SP_TP_BORDER_COLOR_BASE_ADDR, 2);
240
OUT_RELOC(ring, fd_resource(fd6_ctx->border_color_buf)->bo, off, 0, 0);
241
242
u_upload_unmap(fd6_ctx->border_color_uploader);
243
}
244
245
static void
246
fd6_emit_fb_tex(struct fd_ringbuffer *state, struct fd_context *ctx) assert_dt
247
{
248
struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
249
struct pipe_surface *psurf = pfb->cbufs[0];
250
struct fd_resource *rsc = fd_resource(psurf->texture);
251
252
OUT_RINGP(state, 0, &ctx->batch->fb_read_patches); /* texconst0, patched in gmem emit */
253
OUT_RING(state, A6XX_TEX_CONST_1_WIDTH(pfb->width) |
254
A6XX_TEX_CONST_1_HEIGHT(pfb->height));
255
OUT_RING(state, 0); /* texconst2, patched in gmem emit */
256
OUT_RING(state, A6XX_TEX_CONST_3_ARRAY_PITCH(rsc->layout.layer_size));
257
OUT_RING(state, 0); /* BASE_LO, patched in gmem emit */
258
OUT_RING(state, 0); /* BASE_HI, patched in gmem emit */
259
OUT_RING(state, 0); /* texconst6 */
260
OUT_RING(state, 0); /* texconst7 */
261
OUT_RING(state, 0); /* texconst8 */
262
OUT_RING(state, 0); /* texconst9 */
263
OUT_RING(state, 0); /* texconst10 */
264
OUT_RING(state, 0); /* texconst11 */
265
OUT_RING(state, 0);
266
OUT_RING(state, 0);
267
OUT_RING(state, 0);
268
OUT_RING(state, 0);
269
}
270
271
bool
272
fd6_emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
273
enum pipe_shader_type type, struct fd_texture_stateobj *tex,
274
unsigned bcolor_offset,
275
/* can be NULL if no image/SSBO/fb state to merge in: */
276
const struct ir3_shader_variant *v)
277
{
278
bool needs_border = false;
279
unsigned opcode, tex_samp_reg, tex_const_reg, tex_count_reg;
280
enum a6xx_state_block sb;
281
282
switch (type) {
283
case PIPE_SHADER_VERTEX:
284
sb = SB6_VS_TEX;
285
opcode = CP_LOAD_STATE6_GEOM;
286
tex_samp_reg = REG_A6XX_SP_VS_TEX_SAMP;
287
tex_const_reg = REG_A6XX_SP_VS_TEX_CONST;
288
tex_count_reg = REG_A6XX_SP_VS_TEX_COUNT;
289
break;
290
case PIPE_SHADER_TESS_CTRL:
291
sb = SB6_HS_TEX;
292
opcode = CP_LOAD_STATE6_GEOM;
293
tex_samp_reg = REG_A6XX_SP_HS_TEX_SAMP;
294
tex_const_reg = REG_A6XX_SP_HS_TEX_CONST;
295
tex_count_reg = REG_A6XX_SP_HS_TEX_COUNT;
296
break;
297
case PIPE_SHADER_TESS_EVAL:
298
sb = SB6_DS_TEX;
299
opcode = CP_LOAD_STATE6_GEOM;
300
tex_samp_reg = REG_A6XX_SP_DS_TEX_SAMP;
301
tex_const_reg = REG_A6XX_SP_DS_TEX_CONST;
302
tex_count_reg = REG_A6XX_SP_DS_TEX_COUNT;
303
break;
304
case PIPE_SHADER_GEOMETRY:
305
sb = SB6_GS_TEX;
306
opcode = CP_LOAD_STATE6_GEOM;
307
tex_samp_reg = REG_A6XX_SP_GS_TEX_SAMP;
308
tex_const_reg = REG_A6XX_SP_GS_TEX_CONST;
309
tex_count_reg = REG_A6XX_SP_GS_TEX_COUNT;
310
break;
311
case PIPE_SHADER_FRAGMENT:
312
sb = SB6_FS_TEX;
313
opcode = CP_LOAD_STATE6_FRAG;
314
tex_samp_reg = REG_A6XX_SP_FS_TEX_SAMP;
315
tex_const_reg = REG_A6XX_SP_FS_TEX_CONST;
316
tex_count_reg = REG_A6XX_SP_FS_TEX_COUNT;
317
break;
318
case PIPE_SHADER_COMPUTE:
319
sb = SB6_CS_TEX;
320
opcode = CP_LOAD_STATE6_FRAG;
321
tex_samp_reg = REG_A6XX_SP_CS_TEX_SAMP;
322
tex_const_reg = REG_A6XX_SP_CS_TEX_CONST;
323
tex_count_reg = REG_A6XX_SP_CS_TEX_COUNT;
324
break;
325
default:
326
unreachable("bad state block");
327
}
328
329
if (tex->num_samplers > 0) {
330
struct fd_ringbuffer *state =
331
fd_ringbuffer_new_object(ctx->pipe, tex->num_samplers * 4 * 4);
332
for (unsigned i = 0; i < tex->num_samplers; i++) {
333
static const struct fd6_sampler_stateobj dummy_sampler = {};
334
const struct fd6_sampler_stateobj *sampler =
335
tex->samplers[i] ? fd6_sampler_stateobj(tex->samplers[i])
336
: &dummy_sampler;
337
OUT_RING(state, sampler->texsamp0);
338
OUT_RING(state, sampler->texsamp1);
339
OUT_RING(state, sampler->texsamp2 |
340
A6XX_TEX_SAMP_2_BCOLOR(i + bcolor_offset));
341
OUT_RING(state, sampler->texsamp3);
342
needs_border |= sampler->needs_border;
343
}
344
345
/* output sampler state: */
346
OUT_PKT7(ring, opcode, 3);
347
OUT_RING(ring, CP_LOAD_STATE6_0_DST_OFF(0) |
348
CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER) |
349
CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT) |
350
CP_LOAD_STATE6_0_STATE_BLOCK(sb) |
351
CP_LOAD_STATE6_0_NUM_UNIT(tex->num_samplers));
352
OUT_RB(ring, state); /* SRC_ADDR_LO/HI */
353
354
OUT_PKT4(ring, tex_samp_reg, 2);
355
OUT_RB(ring, state); /* SRC_ADDR_LO/HI */
356
357
fd_ringbuffer_del(state);
358
}
359
360
unsigned num_merged_textures = tex->num_textures;
361
unsigned num_textures = tex->num_textures;
362
if (v) {
363
num_merged_textures += v->image_mapping.num_tex;
364
365
if (v->fb_read)
366
num_merged_textures++;
367
368
/* There could be more bound textures than what the shader uses.
369
* Which isn't known at shader compile time. So in the case we
370
* are merging tex state, only emit the textures that the shader
371
* uses (since the image/SSBO related tex state comes immediately
372
* after)
373
*/
374
num_textures = v->image_mapping.tex_base;
375
}
376
377
if (num_merged_textures > 0) {
378
struct fd_ringbuffer *state =
379
fd_ringbuffer_new_object(ctx->pipe, num_merged_textures * 16 * 4);
380
for (unsigned i = 0; i < num_textures; i++) {
381
const struct fd6_pipe_sampler_view *view;
382
383
if (tex->textures[i]) {
384
view = fd6_pipe_sampler_view(tex->textures[i]);
385
if (unlikely(view->rsc_seqno !=
386
fd_resource(view->base.texture)->seqno)) {
387
fd6_sampler_view_update(ctx,
388
fd6_pipe_sampler_view(tex->textures[i]));
389
}
390
} else {
391
static const struct fd6_pipe_sampler_view dummy_view = {};
392
view = &dummy_view;
393
}
394
395
OUT_RING(state, view->texconst0);
396
OUT_RING(state, view->texconst1);
397
OUT_RING(state, view->texconst2);
398
OUT_RING(state, view->texconst3);
399
400
if (view->ptr1) {
401
OUT_RELOC(state, view->ptr1->bo, view->offset1,
402
(uint64_t)view->texconst5 << 32, 0);
403
} else {
404
OUT_RING(state, 0x00000000);
405
OUT_RING(state, view->texconst5);
406
}
407
408
OUT_RING(state, view->texconst6);
409
410
if (view->ptr2) {
411
OUT_RELOC(state, view->ptr2->bo, view->offset2, 0, 0);
412
} else {
413
OUT_RING(state, 0);
414
OUT_RING(state, 0);
415
}
416
417
OUT_RING(state, view->texconst9);
418
OUT_RING(state, view->texconst10);
419
OUT_RING(state, view->texconst11);
420
OUT_RING(state, 0);
421
OUT_RING(state, 0);
422
OUT_RING(state, 0);
423
OUT_RING(state, 0);
424
}
425
426
if (v) {
427
const struct ir3_ibo_mapping *mapping = &v->image_mapping;
428
struct fd_shaderbuf_stateobj *buf = &ctx->shaderbuf[type];
429
struct fd_shaderimg_stateobj *img = &ctx->shaderimg[type];
430
431
for (unsigned i = 0; i < mapping->num_tex; i++) {
432
unsigned idx = mapping->tex_to_image[i];
433
if (idx & IBO_SSBO) {
434
fd6_emit_ssbo_tex(state, &buf->sb[idx & ~IBO_SSBO]);
435
} else {
436
fd6_emit_image_tex(state, &img->si[idx]);
437
}
438
}
439
440
if (v->fb_read) {
441
fd6_emit_fb_tex(state, ctx);
442
}
443
}
444
445
/* emit texture state: */
446
OUT_PKT7(ring, opcode, 3);
447
OUT_RING(ring, CP_LOAD_STATE6_0_DST_OFF(0) |
448
CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS) |
449
CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT) |
450
CP_LOAD_STATE6_0_STATE_BLOCK(sb) |
451
CP_LOAD_STATE6_0_NUM_UNIT(num_merged_textures));
452
OUT_RB(ring, state); /* SRC_ADDR_LO/HI */
453
454
OUT_PKT4(ring, tex_const_reg, 2);
455
OUT_RB(ring, state); /* SRC_ADDR_LO/HI */
456
457
fd_ringbuffer_del(state);
458
}
459
460
OUT_PKT4(ring, tex_count_reg, 1);
461
OUT_RING(ring, num_merged_textures);
462
463
return needs_border;
464
}
465
466
/* Emits combined texture state, which also includes any Image/SSBO
467
* related texture state merged in (because we must have all texture
468
* state for a given stage in a single buffer). In the fast-path, if
469
* we don't need to merge in any image/ssbo related texture state, we
470
* just use cached texture stateobj. Otherwise we generate a single-
471
* use stateobj.
472
*
473
* TODO Is there some sane way we can still use cached texture stateobj
474
* with image/ssbo in use?
475
*
476
* returns whether border_color is required:
477
*/
478
static bool
479
fd6_emit_combined_textures(struct fd_ringbuffer *ring, struct fd6_emit *emit,
480
enum pipe_shader_type type,
481
const struct ir3_shader_variant *v) assert_dt
482
{
483
struct fd_context *ctx = emit->ctx;
484
bool needs_border = false;
485
486
static const struct {
487
enum fd6_state_id state_id;
488
unsigned enable_mask;
489
} s[PIPE_SHADER_TYPES] = {
490
[PIPE_SHADER_VERTEX] = {FD6_GROUP_VS_TEX, ENABLE_ALL},
491
[PIPE_SHADER_TESS_CTRL] = {FD6_GROUP_HS_TEX, ENABLE_ALL},
492
[PIPE_SHADER_TESS_EVAL] = {FD6_GROUP_DS_TEX, ENABLE_ALL},
493
[PIPE_SHADER_GEOMETRY] = {FD6_GROUP_GS_TEX, ENABLE_ALL},
494
[PIPE_SHADER_FRAGMENT] = {FD6_GROUP_FS_TEX, ENABLE_DRAW},
495
};
496
497
debug_assert(s[type].state_id);
498
499
if (!v->image_mapping.num_tex && !v->fb_read) {
500
/* in the fast-path, when we don't have to mix in any image/SSBO
501
* related texture state, we can just lookup the stateobj and
502
* re-emit that:
503
*
504
* Also, framebuffer-read is a slow-path because an extra
505
* texture needs to be inserted.
506
*
507
* TODO we can probably simmplify things if we also treated
508
* border_color as a slow-path.. this way the tex state key
509
* wouldn't depend on bcolor_offset.. but fb_read might rather
510
* be *somehow* a fast-path if we eventually used it for PLS.
511
* I suppose there would be no harm in just *always* inserting
512
* an fb_read texture?
513
*/
514
if ((ctx->dirty_shader[type] & FD_DIRTY_SHADER_TEX) &&
515
ctx->tex[type].num_textures > 0) {
516
struct fd6_texture_state *tex =
517
fd6_texture_state(ctx, type, &ctx->tex[type]);
518
519
needs_border |= tex->needs_border;
520
521
fd6_emit_add_group(emit, tex->stateobj, s[type].state_id,
522
s[type].enable_mask);
523
524
fd6_texture_state_reference(&tex, NULL);
525
}
526
} else {
527
/* In the slow-path, create a one-shot texture state object
528
* if either TEX|PROG|SSBO|IMAGE state is dirty:
529
*/
530
if ((ctx->dirty_shader[type] &
531
(FD_DIRTY_SHADER_TEX | FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_IMAGE |
532
FD_DIRTY_SHADER_SSBO)) ||
533
v->fb_read) {
534
struct fd_texture_stateobj *tex = &ctx->tex[type];
535
struct fd_ringbuffer *stateobj = fd_submit_new_ringbuffer(
536
ctx->batch->submit, 0x1000, FD_RINGBUFFER_STREAMING);
537
unsigned bcolor_offset = fd6_border_color_offset(ctx, type, tex);
538
539
needs_border |=
540
fd6_emit_textures(ctx, stateobj, type, tex, bcolor_offset, v);
541
542
fd6_emit_take_group(emit, stateobj, s[type].state_id,
543
s[type].enable_mask);
544
}
545
}
546
547
return needs_border;
548
}
549
550
static struct fd_ringbuffer *
551
build_vbo_state(struct fd6_emit *emit) assert_dt
552
{
553
const struct fd_vertex_state *vtx = emit->vtx;
554
555
struct fd_ringbuffer *ring = fd_submit_new_ringbuffer(
556
emit->ctx->batch->submit, 4 * (1 + vtx->vertexbuf.count * 4),
557
FD_RINGBUFFER_STREAMING);
558
559
OUT_PKT4(ring, REG_A6XX_VFD_FETCH(0), 4 * vtx->vertexbuf.count);
560
for (int32_t j = 0; j < vtx->vertexbuf.count; j++) {
561
const struct pipe_vertex_buffer *vb = &vtx->vertexbuf.vb[j];
562
struct fd_resource *rsc = fd_resource(vb->buffer.resource);
563
if (rsc == NULL) {
564
OUT_RING(ring, 0);
565
OUT_RING(ring, 0);
566
OUT_RING(ring, 0);
567
OUT_RING(ring, 0);
568
} else {
569
uint32_t off = vb->buffer_offset;
570
uint32_t size = fd_bo_size(rsc->bo) - off;
571
572
OUT_RELOC(ring, rsc->bo, off, 0, 0);
573
OUT_RING(ring, size); /* VFD_FETCH[j].SIZE */
574
OUT_RING(ring, vb->stride); /* VFD_FETCH[j].STRIDE */
575
}
576
}
577
578
return ring;
579
}
580
581
static enum a6xx_ztest_mode
582
compute_ztest_mode(struct fd6_emit *emit, bool lrz_valid) assert_dt
583
{
584
struct fd_context *ctx = emit->ctx;
585
struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
586
struct fd6_zsa_stateobj *zsa = fd6_zsa_stateobj(ctx->zsa);
587
const struct ir3_shader_variant *fs = emit->fs;
588
589
if (fs->shader->nir->info.fs.early_fragment_tests)
590
return A6XX_EARLY_Z;
591
592
if (fs->no_earlyz || fs->writes_pos || !zsa->base.depth_enabled ||
593
fs->writes_stencilref) {
594
return A6XX_LATE_Z;
595
} else if ((fs->has_kill || zsa->alpha_test) &&
596
(zsa->writes_zs || !pfb->zsbuf)) {
597
/* Slightly odd, but seems like the hw wants us to select
598
* LATE_Z mode if there is no depth buffer + discard. Either
599
* that, or when occlusion query is enabled. See:
600
*
601
* dEQP-GLES31.functional.fbo.no_attachments.*
602
*/
603
return lrz_valid ? A6XX_EARLY_LRZ_LATE_Z : A6XX_LATE_Z;
604
} else {
605
return A6XX_EARLY_Z;
606
}
607
}
608
609
/**
610
* Calculate normalized LRZ state based on zsa/prog/blend state, updating
611
* the zsbuf's lrz state as necessary to detect the cases where we need
612
* to invalidate lrz.
613
*/
614
static struct fd6_lrz_state
615
compute_lrz_state(struct fd6_emit *emit, bool binning_pass) assert_dt
616
{
617
struct fd_context *ctx = emit->ctx;
618
struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
619
const struct ir3_shader_variant *fs = emit->fs;
620
struct fd6_lrz_state lrz;
621
622
if (!pfb->zsbuf) {
623
memset(&lrz, 0, sizeof(lrz));
624
if (!binning_pass) {
625
lrz.z_mode = compute_ztest_mode(emit, false);
626
}
627
return lrz;
628
}
629
630
struct fd6_blend_stateobj *blend = fd6_blend_stateobj(ctx->blend);
631
struct fd6_zsa_stateobj *zsa = fd6_zsa_stateobj(ctx->zsa);
632
struct fd_resource *rsc = fd_resource(pfb->zsbuf->texture);
633
634
lrz = zsa->lrz;
635
636
/* normalize lrz state: */
637
if (blend->reads_dest || fs->writes_pos || fs->no_earlyz || fs->has_kill) {
638
lrz.write = false;
639
if (binning_pass)
640
lrz.enable = false;
641
}
642
643
/* if we change depthfunc direction, bail out on using LRZ. The
644
* LRZ buffer encodes a min/max depth value per block, but if
645
* we switch from GT/GE <-> LT/LE, those values cannot be
646
* interpreted properly.
647
*/
648
if (zsa->base.depth_enabled && (rsc->lrz_direction != FD_LRZ_UNKNOWN) &&
649
(rsc->lrz_direction != lrz.direction)) {
650
rsc->lrz_valid = false;
651
}
652
653
if (zsa->invalidate_lrz || !rsc->lrz_valid) {
654
rsc->lrz_valid = false;
655
memset(&lrz, 0, sizeof(lrz));
656
}
657
658
if (fs->no_earlyz || fs->writes_pos) {
659
lrz.enable = false;
660
lrz.write = false;
661
lrz.test = false;
662
}
663
664
if (!binning_pass) {
665
lrz.z_mode = compute_ztest_mode(emit, rsc->lrz_valid);
666
}
667
668
/* Once we start writing to the real depth buffer, we lock in the
669
* direction for LRZ.. if we have to skip a LRZ write for any
670
* reason, it is still safe to have LRZ until there is a direction
671
* reversal. Prior to the reversal, since we disabled LRZ writes
672
* in the "unsafe" cases, this just means that the LRZ test may
673
* not early-discard some things that end up not passing a later
674
* test (ie. be overly concervative). But once you have a reversal
675
* of direction, it is possible to increase/decrease the z value
676
* to the point where the overly-conservative test is incorrect.
677
*/
678
if (zsa->base.depth_writemask) {
679
rsc->lrz_direction = lrz.direction;
680
}
681
682
return lrz;
683
}
684
685
static struct fd_ringbuffer *
686
build_lrz(struct fd6_emit *emit, bool binning_pass) assert_dt
687
{
688
struct fd_context *ctx = emit->ctx;
689
struct fd6_context *fd6_ctx = fd6_context(ctx);
690
struct fd6_lrz_state lrz = compute_lrz_state(emit, binning_pass);
691
692
/* If the LRZ state has not changed, we can skip the emit: */
693
if (!ctx->last.dirty &&
694
!memcmp(&fd6_ctx->last.lrz[binning_pass], &lrz, sizeof(lrz)))
695
return NULL;
696
697
fd6_ctx->last.lrz[binning_pass] = lrz;
698
699
struct fd_ringbuffer *ring = fd_submit_new_ringbuffer(
700
ctx->batch->submit, 8 * 4, FD_RINGBUFFER_STREAMING);
701
702
OUT_REG(ring,
703
A6XX_GRAS_LRZ_CNTL(.enable = lrz.enable, .lrz_write = lrz.write,
704
.greater = lrz.direction == FD_LRZ_GREATER,
705
.z_test_enable = lrz.test, ));
706
OUT_REG(ring, A6XX_RB_LRZ_CNTL(.enable = lrz.enable, ));
707
708
OUT_REG(ring, A6XX_RB_DEPTH_PLANE_CNTL(.z_mode = lrz.z_mode, ));
709
710
OUT_REG(ring, A6XX_GRAS_SU_DEPTH_PLANE_CNTL(.z_mode = lrz.z_mode, ));
711
712
return ring;
713
}
714
715
static struct fd_ringbuffer *
716
build_scissor(struct fd6_emit *emit) assert_dt
717
{
718
struct fd_context *ctx = emit->ctx;
719
struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
720
721
struct fd_ringbuffer *ring = fd_submit_new_ringbuffer(
722
emit->ctx->batch->submit, 3 * 4, FD_RINGBUFFER_STREAMING);
723
724
OUT_REG(
725
ring,
726
A6XX_GRAS_SC_SCREEN_SCISSOR_TL(0, .x = scissor->minx, .y = scissor->miny),
727
A6XX_GRAS_SC_SCREEN_SCISSOR_BR(0, .x = MAX2(scissor->maxx, 1) - 1,
728
.y = MAX2(scissor->maxy, 1) - 1));
729
730
ctx->batch->max_scissor.minx =
731
MIN2(ctx->batch->max_scissor.minx, scissor->minx);
732
ctx->batch->max_scissor.miny =
733
MIN2(ctx->batch->max_scissor.miny, scissor->miny);
734
ctx->batch->max_scissor.maxx =
735
MAX2(ctx->batch->max_scissor.maxx, scissor->maxx);
736
ctx->batch->max_scissor.maxy =
737
MAX2(ctx->batch->max_scissor.maxy, scissor->maxy);
738
739
return ring;
740
}
741
742
/* Combination of FD_DIRTY_FRAMEBUFFER | FD_DIRTY_RASTERIZER_DISCARD |
743
* FD_DIRTY_PROG | FD_DIRTY_DUAL_BLEND
744
*/
745
static struct fd_ringbuffer *
746
build_prog_fb_rast(struct fd6_emit *emit) assert_dt
747
{
748
struct fd_context *ctx = emit->ctx;
749
struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
750
const struct fd6_program_state *prog = fd6_emit_get_prog(emit);
751
const struct ir3_shader_variant *fs = emit->fs;
752
753
struct fd_ringbuffer *ring = fd_submit_new_ringbuffer(
754
ctx->batch->submit, 9 * 4, FD_RINGBUFFER_STREAMING);
755
756
unsigned nr = pfb->nr_cbufs;
757
758
if (ctx->rasterizer->rasterizer_discard)
759
nr = 0;
760
761
struct fd6_blend_stateobj *blend = fd6_blend_stateobj(ctx->blend);
762
763
if (blend->use_dual_src_blend)
764
nr++;
765
766
OUT_PKT4(ring, REG_A6XX_RB_FS_OUTPUT_CNTL0, 2);
767
OUT_RING(ring, COND(fs->writes_pos, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z) |
768
COND(fs->writes_smask && pfb->samples > 1,
769
A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_SAMPMASK) |
770
COND(fs->writes_stencilref,
771
A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_STENCILREF) |
772
COND(blend->use_dual_src_blend,
773
A6XX_RB_FS_OUTPUT_CNTL0_DUAL_COLOR_IN_ENABLE));
774
OUT_RING(ring, A6XX_RB_FS_OUTPUT_CNTL1_MRT(nr));
775
776
OUT_PKT4(ring, REG_A6XX_SP_FS_OUTPUT_CNTL1, 1);
777
OUT_RING(ring, A6XX_SP_FS_OUTPUT_CNTL1_MRT(nr));
778
779
unsigned mrt_components = 0;
780
for (unsigned i = 0; i < pfb->nr_cbufs; i++) {
781
if (!pfb->cbufs[i])
782
continue;
783
mrt_components |= 0xf << (i * 4);
784
}
785
786
/* dual source blending has an extra fs output in the 2nd slot */
787
if (blend->use_dual_src_blend)
788
mrt_components |= 0xf << 4;
789
790
mrt_components &= prog->mrt_components;
791
792
OUT_REG(ring, A6XX_SP_FS_RENDER_COMPONENTS(.dword = mrt_components));
793
OUT_REG(ring, A6XX_RB_RENDER_COMPONENTS(.dword = mrt_components));
794
795
return ring;
796
}
797
798
static struct fd_ringbuffer *
799
build_blend_color(struct fd6_emit *emit) assert_dt
800
{
801
struct fd_context *ctx = emit->ctx;
802
struct pipe_blend_color *bcolor = &ctx->blend_color;
803
struct fd_ringbuffer *ring = fd_submit_new_ringbuffer(
804
ctx->batch->submit, 5 * 4, FD_RINGBUFFER_STREAMING);
805
806
OUT_REG(ring, A6XX_RB_BLEND_RED_F32(bcolor->color[0]),
807
A6XX_RB_BLEND_GREEN_F32(bcolor->color[1]),
808
A6XX_RB_BLEND_BLUE_F32(bcolor->color[2]),
809
A6XX_RB_BLEND_ALPHA_F32(bcolor->color[3]));
810
811
return ring;
812
}
813
814
static struct fd_ringbuffer *
815
build_ibo(struct fd6_emit *emit) assert_dt
816
{
817
struct fd_context *ctx = emit->ctx;
818
819
if (emit->hs) {
820
debug_assert(ir3_shader_nibo(emit->hs) == 0);
821
debug_assert(ir3_shader_nibo(emit->ds) == 0);
822
}
823
if (emit->gs) {
824
debug_assert(ir3_shader_nibo(emit->gs) == 0);
825
}
826
827
struct fd_ringbuffer *ibo_state =
828
fd6_build_ibo_state(ctx, emit->fs, PIPE_SHADER_FRAGMENT);
829
struct fd_ringbuffer *ring = fd_submit_new_ringbuffer(
830
ctx->batch->submit, 0x100, FD_RINGBUFFER_STREAMING);
831
832
OUT_PKT7(ring, CP_LOAD_STATE6, 3);
833
OUT_RING(ring, CP_LOAD_STATE6_0_DST_OFF(0) |
834
CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER) |
835
CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT) |
836
CP_LOAD_STATE6_0_STATE_BLOCK(SB6_IBO) |
837
CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(emit->fs)));
838
OUT_RB(ring, ibo_state);
839
840
OUT_PKT4(ring, REG_A6XX_SP_IBO, 2);
841
OUT_RB(ring, ibo_state);
842
843
/* TODO if we used CP_SET_DRAW_STATE for compute shaders, we could
844
* de-duplicate this from program->config_stateobj
845
*/
846
OUT_PKT4(ring, REG_A6XX_SP_IBO_COUNT, 1);
847
OUT_RING(ring, ir3_shader_nibo(emit->fs));
848
849
fd_ringbuffer_del(ibo_state);
850
851
return ring;
852
}
853
854
static void
855
fd6_emit_streamout(struct fd_ringbuffer *ring, struct fd6_emit *emit) assert_dt
856
{
857
struct fd_context *ctx = emit->ctx;
858
const struct fd6_program_state *prog = fd6_emit_get_prog(emit);
859
struct ir3_stream_output_info *info = prog->stream_output;
860
struct fd_streamout_stateobj *so = &ctx->streamout;
861
862
emit->streamout_mask = 0;
863
864
if (!info)
865
return;
866
867
for (unsigned i = 0; i < so->num_targets; i++) {
868
struct fd_stream_output_target *target =
869
fd_stream_output_target(so->targets[i]);
870
871
if (!target)
872
continue;
873
874
target->stride = info->stride[i];
875
876
OUT_PKT4(ring, REG_A6XX_VPC_SO_BUFFER_BASE(i), 3);
877
/* VPC_SO[i].BUFFER_BASE_LO: */
878
OUT_RELOC(ring, fd_resource(target->base.buffer)->bo, 0, 0, 0);
879
OUT_RING(ring, target->base.buffer_size + target->base.buffer_offset);
880
881
struct fd_bo *offset_bo = fd_resource(target->offset_buf)->bo;
882
883
if (so->reset & (1 << i)) {
884
assert(so->offsets[i] == 0);
885
886
OUT_PKT7(ring, CP_MEM_WRITE, 3);
887
OUT_RELOC(ring, offset_bo, 0, 0, 0);
888
OUT_RING(ring, target->base.buffer_offset);
889
890
OUT_PKT4(ring, REG_A6XX_VPC_SO_BUFFER_OFFSET(i), 1);
891
OUT_RING(ring, target->base.buffer_offset);
892
} else {
893
OUT_PKT7(ring, CP_MEM_TO_REG, 3);
894
OUT_RING(ring, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(i)) |
895
CP_MEM_TO_REG_0_SHIFT_BY_2 | CP_MEM_TO_REG_0_UNK31 |
896
CP_MEM_TO_REG_0_CNT(0));
897
OUT_RELOC(ring, offset_bo, 0, 0, 0);
898
}
899
900
// After a draw HW would write the new offset to offset_bo
901
OUT_PKT4(ring, REG_A6XX_VPC_SO_FLUSH_BASE(i), 2);
902
OUT_RELOC(ring, offset_bo, 0, 0, 0);
903
904
so->reset &= ~(1 << i);
905
906
emit->streamout_mask |= (1 << i);
907
}
908
909
if (emit->streamout_mask) {
910
fd6_emit_add_group(emit, prog->streamout_stateobj, FD6_GROUP_SO,
911
ENABLE_ALL);
912
} else {
913
/* If we transition from a draw with streamout to one without, turn
914
* off streamout.
915
*/
916
if (ctx->last.streamout_mask != 0) {
917
struct fd_ringbuffer *obj = fd_submit_new_ringbuffer(
918
emit->ctx->batch->submit, 5 * 4, FD_RINGBUFFER_STREAMING);
919
920
OUT_PKT7(obj, CP_CONTEXT_REG_BUNCH, 4);
921
OUT_RING(obj, REG_A6XX_VPC_SO_CNTL);
922
OUT_RING(obj, 0);
923
OUT_RING(obj, REG_A6XX_VPC_SO_STREAM_CNTL);
924
OUT_RING(obj, 0);
925
926
fd6_emit_take_group(emit, obj, FD6_GROUP_SO, ENABLE_ALL);
927
}
928
}
929
930
ctx->last.streamout_mask = emit->streamout_mask;
931
}
932
933
/**
934
* Stuff that less frequently changes and isn't (yet) moved into stategroups
935
*/
936
static void
937
fd6_emit_non_ring(struct fd_ringbuffer *ring, struct fd6_emit *emit) assert_dt
938
{
939
struct fd_context *ctx = emit->ctx;
940
const enum fd_dirty_3d_state dirty = emit->dirty;
941
942
if (dirty & FD_DIRTY_STENCIL_REF) {
943
struct pipe_stencil_ref *sr = &ctx->stencil_ref;
944
945
OUT_PKT4(ring, REG_A6XX_RB_STENCILREF, 1);
946
OUT_RING(ring, A6XX_RB_STENCILREF_REF(sr->ref_value[0]) |
947
A6XX_RB_STENCILREF_BFREF(sr->ref_value[1]));
948
}
949
950
if (dirty & FD_DIRTY_VIEWPORT) {
951
struct pipe_scissor_state *scissor = &ctx->viewport_scissor;
952
953
OUT_REG(ring, A6XX_GRAS_CL_VPORT_XOFFSET(0, ctx->viewport.translate[0]),
954
A6XX_GRAS_CL_VPORT_XSCALE(0, ctx->viewport.scale[0]),
955
A6XX_GRAS_CL_VPORT_YOFFSET(0, ctx->viewport.translate[1]),
956
A6XX_GRAS_CL_VPORT_YSCALE(0, ctx->viewport.scale[1]),
957
A6XX_GRAS_CL_VPORT_ZOFFSET(0, ctx->viewport.translate[2]),
958
A6XX_GRAS_CL_VPORT_ZSCALE(0, ctx->viewport.scale[2]));
959
960
OUT_REG(
961
ring,
962
A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL(0, .x = scissor->minx,
963
.y = scissor->miny),
964
A6XX_GRAS_SC_VIEWPORT_SCISSOR_BR(0, .x = MAX2(scissor->maxx, 1) - 1,
965
.y = MAX2(scissor->maxy, 1) - 1));
966
967
unsigned guardband_x = fd_calc_guardband(ctx->viewport.translate[0],
968
ctx->viewport.scale[0], false);
969
unsigned guardband_y = fd_calc_guardband(ctx->viewport.translate[1],
970
ctx->viewport.scale[1], false);
971
972
OUT_REG(ring, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ(.horz = guardband_x,
973
.vert = guardband_y));
974
}
975
976
/* The clamp ranges are only used when the rasterizer wants depth
977
* clamping.
978
*/
979
if ((dirty & (FD_DIRTY_VIEWPORT | FD_DIRTY_RASTERIZER)) &&
980
fd_depth_clamp_enabled(ctx)) {
981
float zmin, zmax;
982
util_viewport_zmin_zmax(&ctx->viewport, ctx->rasterizer->clip_halfz,
983
&zmin, &zmax);
984
985
OUT_REG(ring, A6XX_GRAS_CL_Z_CLAMP_MIN(0, zmin),
986
A6XX_GRAS_CL_Z_CLAMP_MAX(0, zmax));
987
988
OUT_REG(ring, A6XX_RB_Z_CLAMP_MIN(zmin), A6XX_RB_Z_CLAMP_MAX(zmax));
989
}
990
}
991
992
void
993
fd6_emit_state(struct fd_ringbuffer *ring, struct fd6_emit *emit)
994
{
995
struct fd_context *ctx = emit->ctx;
996
struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
997
const struct fd6_program_state *prog = fd6_emit_get_prog(emit);
998
const struct ir3_shader_variant *vs = emit->vs;
999
const struct ir3_shader_variant *hs = emit->hs;
1000
const struct ir3_shader_variant *ds = emit->ds;
1001
const struct ir3_shader_variant *gs = emit->gs;
1002
const struct ir3_shader_variant *fs = emit->fs;
1003
bool needs_border = false;
1004
1005
emit_marker6(ring, 5);
1006
1007
/* NOTE: we track fb_read differently than _BLEND_ENABLED since we
1008
* might decide to do sysmem in some cases when blend is enabled:
1009
*/
1010
if (fs->fb_read)
1011
ctx->batch->gmem_reason |= FD_GMEM_FB_READ;
1012
1013
u_foreach_bit (b, emit->dirty_groups) {
1014
enum fd6_state_id group = b;
1015
struct fd_ringbuffer *state = NULL;
1016
uint32_t enable_mask = ENABLE_ALL;
1017
1018
switch (group) {
1019
case FD6_GROUP_VTXSTATE:
1020
state = fd6_vertex_stateobj(ctx->vtx.vtx)->stateobj;
1021
fd_ringbuffer_ref(state);
1022
break;
1023
case FD6_GROUP_VBO:
1024
state = build_vbo_state(emit);
1025
break;
1026
case FD6_GROUP_ZSA:
1027
state = fd6_zsa_state(
1028
ctx,
1029
util_format_is_pure_integer(pipe_surface_format(pfb->cbufs[0])),
1030
fd_depth_clamp_enabled(ctx));
1031
fd_ringbuffer_ref(state);
1032
break;
1033
case FD6_GROUP_LRZ:
1034
state = build_lrz(emit, false);
1035
if (!state)
1036
continue;
1037
enable_mask = ENABLE_DRAW;
1038
break;
1039
case FD6_GROUP_LRZ_BINNING:
1040
state = build_lrz(emit, true);
1041
if (!state)
1042
continue;
1043
enable_mask = CP_SET_DRAW_STATE__0_BINNING;
1044
break;
1045
case FD6_GROUP_SCISSOR:
1046
state = build_scissor(emit);
1047
break;
1048
case FD6_GROUP_PROG:
1049
fd6_emit_add_group(emit, prog->config_stateobj, FD6_GROUP_PROG_CONFIG,
1050
ENABLE_ALL);
1051
fd6_emit_add_group(emit, prog->stateobj, FD6_GROUP_PROG, ENABLE_DRAW);
1052
fd6_emit_add_group(emit, prog->binning_stateobj,
1053
FD6_GROUP_PROG_BINNING,
1054
CP_SET_DRAW_STATE__0_BINNING);
1055
1056
/* emit remaining streaming program state, ie. what depends on
1057
* other emit state, so cannot be pre-baked.
1058
*/
1059
fd6_emit_take_group(emit, fd6_program_interp_state(emit),
1060
FD6_GROUP_PROG_INTERP, ENABLE_DRAW);
1061
continue;
1062
case FD6_GROUP_RASTERIZER:
1063
state = fd6_rasterizer_state(ctx, emit->primitive_restart);
1064
fd_ringbuffer_ref(state);
1065
break;
1066
case FD6_GROUP_PROG_FB_RAST:
1067
state = build_prog_fb_rast(emit);
1068
break;
1069
case FD6_GROUP_BLEND:
1070
state = fd6_blend_variant(ctx->blend, pfb->samples, ctx->sample_mask)
1071
->stateobj;
1072
fd_ringbuffer_ref(state);
1073
break;
1074
case FD6_GROUP_BLEND_COLOR:
1075
state = build_blend_color(emit);
1076
break;
1077
case FD6_GROUP_IBO:
1078
state = build_ibo(emit);
1079
fd6_emit_ibo_consts(emit, fs, PIPE_SHADER_FRAGMENT, ring);
1080
break;
1081
case FD6_GROUP_CONST:
1082
state = fd6_build_user_consts(emit);
1083
break;
1084
case FD6_GROUP_VS_DRIVER_PARAMS:
1085
state = fd6_build_vs_driver_params(emit);
1086
break;
1087
case FD6_GROUP_PRIMITIVE_PARAMS:
1088
state = fd6_build_tess_consts(emit);
1089
break;
1090
case FD6_GROUP_VS_TEX:
1091
needs_border |=
1092
fd6_emit_combined_textures(ring, emit, PIPE_SHADER_VERTEX, vs);
1093
continue;
1094
case FD6_GROUP_HS_TEX:
1095
if (hs) {
1096
needs_border |= fd6_emit_combined_textures(
1097
ring, emit, PIPE_SHADER_TESS_CTRL, hs);
1098
}
1099
continue;
1100
case FD6_GROUP_DS_TEX:
1101
if (ds) {
1102
needs_border |= fd6_emit_combined_textures(
1103
ring, emit, PIPE_SHADER_TESS_EVAL, ds);
1104
}
1105
continue;
1106
case FD6_GROUP_GS_TEX:
1107
if (gs) {
1108
needs_border |=
1109
fd6_emit_combined_textures(ring, emit, PIPE_SHADER_GEOMETRY, gs);
1110
}
1111
continue;
1112
case FD6_GROUP_FS_TEX:
1113
needs_border |=
1114
fd6_emit_combined_textures(ring, emit, PIPE_SHADER_FRAGMENT, fs);
1115
continue;
1116
case FD6_GROUP_SO:
1117
fd6_emit_streamout(ring, emit);
1118
continue;
1119
case FD6_GROUP_NON_GROUP:
1120
fd6_emit_non_ring(ring, emit);
1121
continue;
1122
default:
1123
unreachable("bad state group");
1124
}
1125
1126
fd6_emit_take_group(emit, state, group, enable_mask);
1127
}
1128
1129
if (needs_border)
1130
emit_border_color(ctx, ring);
1131
1132
if (emit->num_groups > 0) {
1133
OUT_PKT7(ring, CP_SET_DRAW_STATE, 3 * emit->num_groups);
1134
for (unsigned i = 0; i < emit->num_groups; i++) {
1135
struct fd6_state_group *g = &emit->groups[i];
1136
unsigned n = g->stateobj ? fd_ringbuffer_size(g->stateobj) / 4 : 0;
1137
1138
debug_assert((g->enable_mask & ~ENABLE_ALL) == 0);
1139
1140
if (n == 0) {
1141
OUT_RING(ring, CP_SET_DRAW_STATE__0_COUNT(0) |
1142
CP_SET_DRAW_STATE__0_DISABLE | g->enable_mask |
1143
CP_SET_DRAW_STATE__0_GROUP_ID(g->group_id));
1144
OUT_RING(ring, 0x00000000);
1145
OUT_RING(ring, 0x00000000);
1146
} else {
1147
OUT_RING(ring, CP_SET_DRAW_STATE__0_COUNT(n) | g->enable_mask |
1148
CP_SET_DRAW_STATE__0_GROUP_ID(g->group_id));
1149
OUT_RB(ring, g->stateobj);
1150
}
1151
1152
if (g->stateobj)
1153
fd_ringbuffer_del(g->stateobj);
1154
}
1155
emit->num_groups = 0;
1156
}
1157
}
1158
1159
void
1160
fd6_emit_cs_state(struct fd_context *ctx, struct fd_ringbuffer *ring,
1161
struct ir3_shader_variant *cp)
1162
{
1163
enum fd_dirty_shader_state dirty = ctx->dirty_shader[PIPE_SHADER_COMPUTE];
1164
1165
if (dirty & (FD_DIRTY_SHADER_TEX | FD_DIRTY_SHADER_PROG |
1166
FD_DIRTY_SHADER_IMAGE | FD_DIRTY_SHADER_SSBO)) {
1167
struct fd_texture_stateobj *tex = &ctx->tex[PIPE_SHADER_COMPUTE];
1168
unsigned bcolor_offset =
1169
fd6_border_color_offset(ctx, PIPE_SHADER_COMPUTE, tex);
1170
1171
bool needs_border = fd6_emit_textures(ctx, ring, PIPE_SHADER_COMPUTE, tex,
1172
bcolor_offset, cp);
1173
1174
if (needs_border)
1175
emit_border_color(ctx, ring);
1176
1177
OUT_PKT4(ring, REG_A6XX_SP_VS_TEX_COUNT, 1);
1178
OUT_RING(ring, 0);
1179
1180
OUT_PKT4(ring, REG_A6XX_SP_HS_TEX_COUNT, 1);
1181
OUT_RING(ring, 0);
1182
1183
OUT_PKT4(ring, REG_A6XX_SP_DS_TEX_COUNT, 1);
1184
OUT_RING(ring, 0);
1185
1186
OUT_PKT4(ring, REG_A6XX_SP_GS_TEX_COUNT, 1);
1187
OUT_RING(ring, 0);
1188
1189
OUT_PKT4(ring, REG_A6XX_SP_FS_TEX_COUNT, 1);
1190
OUT_RING(ring, 0);
1191
}
1192
1193
if (dirty & (FD_DIRTY_SHADER_SSBO | FD_DIRTY_SHADER_IMAGE)) {
1194
struct fd_ringbuffer *state =
1195
fd6_build_ibo_state(ctx, cp, PIPE_SHADER_COMPUTE);
1196
1197
OUT_PKT7(ring, CP_LOAD_STATE6_FRAG, 3);
1198
OUT_RING(ring, CP_LOAD_STATE6_0_DST_OFF(0) |
1199
CP_LOAD_STATE6_0_STATE_TYPE(ST6_IBO) |
1200
CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT) |
1201
CP_LOAD_STATE6_0_STATE_BLOCK(SB6_CS_SHADER) |
1202
CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(cp)));
1203
OUT_RB(ring, state);
1204
1205
OUT_PKT4(ring, REG_A6XX_SP_CS_IBO, 2);
1206
OUT_RB(ring, state);
1207
1208
OUT_PKT4(ring, REG_A6XX_SP_CS_IBO_COUNT, 1);
1209
OUT_RING(ring, ir3_shader_nibo(cp));
1210
1211
fd_ringbuffer_del(state);
1212
}
1213
}
1214
1215
/* emit setup at begin of new cmdstream buffer (don't rely on previous
1216
* state, there could have been a context switch between ioctls):
1217
*/
1218
void
1219
fd6_emit_restore(struct fd_batch *batch, struct fd_ringbuffer *ring)
1220
{
1221
// struct fd_context *ctx = batch->ctx;
1222
1223
if (!batch->nondraw) {
1224
trace_start_state_restore(&batch->trace);
1225
}
1226
1227
fd6_cache_inv(batch, ring);
1228
1229
OUT_REG(ring,
1230
A6XX_HLSQ_INVALIDATE_CMD(.vs_state = true, .hs_state = true,
1231
.ds_state = true, .gs_state = true,
1232
.fs_state = true, .cs_state = true,
1233
.gfx_ibo = true, .cs_ibo = true,
1234
.gfx_shared_const = true,
1235
.cs_shared_const = true,
1236
.gfx_bindless = 0x1f, .cs_bindless = 0x1f));
1237
1238
OUT_WFI5(ring);
1239
1240
WRITE(REG_A6XX_RB_UNKNOWN_8E04, 0x0);
1241
WRITE(REG_A6XX_SP_FLOAT_CNTL, A6XX_SP_FLOAT_CNTL_F16_NO_INF);
1242
WRITE(REG_A6XX_SP_UNKNOWN_AE00, 0);
1243
WRITE(REG_A6XX_SP_PERFCTR_ENABLE, 0x3f);
1244
WRITE(REG_A6XX_TPL1_UNKNOWN_B605, 0x44);
1245
WRITE(REG_A6XX_TPL1_UNKNOWN_B600, 0x100000);
1246
WRITE(REG_A6XX_HLSQ_UNKNOWN_BE00, 0x80);
1247
WRITE(REG_A6XX_HLSQ_UNKNOWN_BE01, 0);
1248
1249
WRITE(REG_A6XX_VPC_UNKNOWN_9600, 0);
1250
WRITE(REG_A6XX_GRAS_UNKNOWN_8600, 0x880);
1251
WRITE(REG_A6XX_HLSQ_UNKNOWN_BE04, 0x80000);
1252
WRITE(REG_A6XX_SP_UNKNOWN_AE03, 0x1430);
1253
WRITE(REG_A6XX_SP_IBO_COUNT, 0);
1254
WRITE(REG_A6XX_SP_UNKNOWN_B182, 0);
1255
WRITE(REG_A6XX_HLSQ_SHARED_CONSTS, 0);
1256
WRITE(REG_A6XX_UCHE_UNKNOWN_0E12, 0x3200000);
1257
WRITE(REG_A6XX_UCHE_CLIENT_PF, 4);
1258
WRITE(REG_A6XX_RB_UNKNOWN_8E01, 0x1);
1259
WRITE(REG_A6XX_SP_MODE_CONTROL,
1260
A6XX_SP_MODE_CONTROL_CONSTANT_DEMOTION_ENABLE | 4);
1261
WRITE(REG_A6XX_VFD_ADD_OFFSET, A6XX_VFD_ADD_OFFSET_VERTEX);
1262
WRITE(REG_A6XX_RB_UNKNOWN_8811, 0x00000010);
1263
WRITE(REG_A6XX_PC_MODE_CNTL, 0x1f);
1264
1265
WRITE(REG_A6XX_GRAS_UNKNOWN_8101, 0);
1266
WRITE(REG_A6XX_GRAS_SAMPLE_CNTL, 0);
1267
WRITE(REG_A6XX_GRAS_UNKNOWN_8110, 0x2);
1268
1269
WRITE(REG_A6XX_RB_UNKNOWN_8818, 0);
1270
WRITE(REG_A6XX_RB_UNKNOWN_8819, 0);
1271
WRITE(REG_A6XX_RB_UNKNOWN_881A, 0);
1272
WRITE(REG_A6XX_RB_UNKNOWN_881B, 0);
1273
WRITE(REG_A6XX_RB_UNKNOWN_881C, 0);
1274
WRITE(REG_A6XX_RB_UNKNOWN_881D, 0);
1275
WRITE(REG_A6XX_RB_UNKNOWN_881E, 0);
1276
WRITE(REG_A6XX_RB_UNKNOWN_88F0, 0);
1277
1278
WRITE(REG_A6XX_VPC_POINT_COORD_INVERT, A6XX_VPC_POINT_COORD_INVERT(0).value);
1279
WRITE(REG_A6XX_VPC_UNKNOWN_9300, 0);
1280
1281
WRITE(REG_A6XX_VPC_SO_DISABLE, A6XX_VPC_SO_DISABLE(true).value);
1282
1283
WRITE(REG_A6XX_PC_RASTER_CNTL, 0);
1284
1285
WRITE(REG_A6XX_PC_MULTIVIEW_CNTL, 0);
1286
1287
WRITE(REG_A6XX_SP_UNKNOWN_B183, 0);
1288
1289
WRITE(REG_A6XX_GRAS_UNKNOWN_8099, 0);
1290
WRITE(REG_A6XX_GRAS_VS_LAYER_CNTL, 0);
1291
WRITE(REG_A6XX_GRAS_UNKNOWN_80A0, 2);
1292
WRITE(REG_A6XX_GRAS_UNKNOWN_80AF, 0);
1293
WRITE(REG_A6XX_VPC_UNKNOWN_9210, 0);
1294
WRITE(REG_A6XX_VPC_UNKNOWN_9211, 0);
1295
WRITE(REG_A6XX_VPC_UNKNOWN_9602, 0);
1296
WRITE(REG_A6XX_PC_UNKNOWN_9E72, 0);
1297
WRITE(REG_A6XX_SP_TP_SAMPLE_CONFIG, 0);
1298
/* NOTE blob seems to (mostly?) use 0xb2 for SP_TP_UNKNOWN_B309
1299
* but this seems to kill texture gather offsets.
1300
*/
1301
WRITE(REG_A6XX_SP_TP_UNKNOWN_B309, 0xa2);
1302
WRITE(REG_A6XX_RB_SAMPLE_CONFIG, 0);
1303
WRITE(REG_A6XX_GRAS_SAMPLE_CONFIG, 0);
1304
WRITE(REG_A6XX_RB_Z_BOUNDS_MIN, 0);
1305
WRITE(REG_A6XX_RB_Z_BOUNDS_MAX, 0);
1306
WRITE(REG_A6XX_HLSQ_CONTROL_5_REG, 0xfc);
1307
1308
emit_marker6(ring, 7);
1309
1310
OUT_PKT4(ring, REG_A6XX_VFD_MODE_CNTL, 1);
1311
OUT_RING(ring, 0x00000000); /* VFD_MODE_CNTL */
1312
1313
WRITE(REG_A6XX_VFD_MULTIVIEW_CNTL, 0);
1314
1315
OUT_PKT4(ring, REG_A6XX_PC_MODE_CNTL, 1);
1316
OUT_RING(ring, 0x0000001f); /* PC_MODE_CNTL */
1317
1318
/* Clear any potential pending state groups to be safe: */
1319
OUT_PKT7(ring, CP_SET_DRAW_STATE, 3);
1320
OUT_RING(ring, CP_SET_DRAW_STATE__0_COUNT(0) |
1321
CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS |
1322
CP_SET_DRAW_STATE__0_GROUP_ID(0));
1323
OUT_RING(ring, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1324
OUT_RING(ring, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1325
1326
OUT_PKT4(ring, REG_A6XX_VPC_SO_STREAM_CNTL, 1);
1327
OUT_RING(ring, 0x00000000); /* VPC_SO_STREAM_CNTL */
1328
1329
OUT_PKT4(ring, REG_A6XX_GRAS_LRZ_CNTL, 1);
1330
OUT_RING(ring, 0x00000000);
1331
1332
OUT_PKT4(ring, REG_A6XX_RB_LRZ_CNTL, 1);
1333
OUT_RING(ring, 0x00000000);
1334
1335
if (!batch->nondraw) {
1336
trace_end_state_restore(&batch->trace);
1337
}
1338
}
1339
1340
static void
1341
fd6_mem_to_mem(struct fd_ringbuffer *ring, struct pipe_resource *dst,
1342
unsigned dst_off, struct pipe_resource *src, unsigned src_off,
1343
unsigned sizedwords)
1344
{
1345
struct fd_bo *src_bo = fd_resource(src)->bo;
1346
struct fd_bo *dst_bo = fd_resource(dst)->bo;
1347
unsigned i;
1348
1349
for (i = 0; i < sizedwords; i++) {
1350
OUT_PKT7(ring, CP_MEM_TO_MEM, 5);
1351
OUT_RING(ring, 0x00000000);
1352
OUT_RELOC(ring, dst_bo, dst_off, 0, 0);
1353
OUT_RELOC(ring, src_bo, src_off, 0, 0);
1354
1355
dst_off += 4;
1356
src_off += 4;
1357
}
1358
}
1359
1360
/* this is *almost* the same as fd6_cache_flush().. which I guess
1361
* could be re-worked to be something a bit more generic w/ param
1362
* indicating what needs to be flushed.. although that would mean
1363
* figuring out which events trigger what state to flush..
1364
*/
1365
static void
1366
fd6_framebuffer_barrier(struct fd_context *ctx) assert_dt
1367
{
1368
struct fd6_context *fd6_ctx = fd6_context(ctx);
1369
struct fd_batch *batch = fd_context_batch_locked(ctx);
1370
struct fd_ringbuffer *ring = batch->draw;
1371
unsigned seqno;
1372
1373
fd_batch_needs_flush(batch);
1374
1375
seqno = fd6_event_write(batch, ring, RB_DONE_TS, true);
1376
1377
OUT_PKT7(ring, CP_WAIT_REG_MEM, 6);
1378
OUT_RING(ring, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ) |
1379
CP_WAIT_REG_MEM_0_POLL_MEMORY);
1380
OUT_RELOC(ring, control_ptr(fd6_ctx, seqno));
1381
OUT_RING(ring, CP_WAIT_REG_MEM_3_REF(seqno));
1382
OUT_RING(ring, CP_WAIT_REG_MEM_4_MASK(~0));
1383
OUT_RING(ring, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(16));
1384
1385
fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
1386
fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);
1387
1388
seqno = fd6_event_write(batch, ring, CACHE_FLUSH_TS, true);
1389
1390
fd6_event_write(batch, ring, 0x31, false);
1391
1392
OUT_PKT7(ring, CP_WAIT_MEM_GTE, 4);
1393
OUT_RING(ring, CP_WAIT_MEM_GTE_0_RESERVED(0));
1394
OUT_RELOC(ring, control_ptr(fd6_ctx, seqno));
1395
OUT_RING(ring, CP_WAIT_MEM_GTE_3_REF(seqno));
1396
1397
fd_batch_unlock_submit(batch);
1398
fd_batch_reference(&batch, NULL);
1399
}
1400
1401
void
1402
fd6_emit_init_screen(struct pipe_screen *pscreen)
1403
{
1404
struct fd_screen *screen = fd_screen(pscreen);
1405
screen->emit_ib = fd6_emit_ib;
1406
screen->mem_to_mem = fd6_mem_to_mem;
1407
}
1408
1409
void
1410
fd6_emit_init(struct pipe_context *pctx) disable_thread_safety_analysis
1411
{
1412
struct fd_context *ctx = fd_context(pctx);
1413
ctx->framebuffer_barrier = fd6_framebuffer_barrier;
1414
}
1415
1416