1 /*
2 * Copyright © 2013 Rob Clark <[email protected]>
3 * SPDX-License-Identifier: MIT
4 *
5 * Authors:
6 * Rob Clark <[email protected]>
7 */
8
9 #include "pipe/p_screen.h"
10 #include "util/format/u_format.h"
11
12 #include "fd3_context.h"
13 #include "fd3_emit.h"
14 #include "fd3_format.h"
15 #include "fd3_resource.h"
16 #include "fd3_screen.h"
17
18 #include "ir3/ir3_compiler.h"
19
20 static bool
fd3_screen_is_format_supported(struct pipe_screen * pscreen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned usage)21 fd3_screen_is_format_supported(struct pipe_screen *pscreen,
22 enum pipe_format format,
23 enum pipe_texture_target target,
24 unsigned sample_count,
25 unsigned storage_sample_count, unsigned usage)
26 {
27 unsigned retval = 0;
28
29 if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
30 (sample_count > 1)) { /* TODO add MSAA */
31 DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
32 util_format_name(format), target, sample_count, usage);
33 return false;
34 }
35
36 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
37 return false;
38
39 if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
40 (fd3_pipe2vtx(format) != VFMT_NONE)) {
41 retval |= PIPE_BIND_VERTEX_BUFFER;
42 }
43
44 if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
45 (fd3_pipe2tex(format) != TFMT_NONE)) {
46 retval |= PIPE_BIND_SAMPLER_VIEW;
47 }
48
49 if ((usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
50 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_BLENDABLE)) &&
51 (fd3_pipe2color(format) != RB_NONE) &&
52 (fd3_pipe2tex(format) != TFMT_NONE)) {
53 retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
54 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
55 if (!util_format_is_pure_integer(format))
56 retval |= usage & PIPE_BIND_BLENDABLE;
57 }
58
59 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
60 (fd_pipe2depth(format) != (enum adreno_rb_depth_format) ~0) &&
61 (fd3_pipe2tex(format) != TFMT_NONE)) {
62 retval |= PIPE_BIND_DEPTH_STENCIL;
63 }
64
65 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
66 (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
67 retval |= PIPE_BIND_INDEX_BUFFER;
68 }
69
70 if (retval != usage) {
71 DBG("not supported: format=%s, target=%d, sample_count=%d, "
72 "usage=%x, retval=%x",
73 util_format_name(format), target, sample_count, usage, retval);
74 }
75
76 return retval == usage;
77 }
78
79 /* clang-format off */
80 static const enum pc_di_primtype primtypes[] = {
81 [MESA_PRIM_POINTS] = DI_PT_POINTLIST,
82 [MESA_PRIM_LINES] = DI_PT_LINELIST,
83 [MESA_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
84 [MESA_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
85 [MESA_PRIM_TRIANGLES] = DI_PT_TRILIST,
86 [MESA_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
87 [MESA_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
88 [MESA_PRIM_COUNT] = DI_PT_RECTLIST, /* internal clear blits */
89 };
90 /* clang-format on */
91
92 void
fd3_screen_init(struct pipe_screen * pscreen)93 fd3_screen_init(struct pipe_screen *pscreen)
94 {
95 struct fd_screen *screen = fd_screen(pscreen);
96 screen->max_rts = A3XX_MAX_RENDER_TARGETS;
97 pscreen->context_create = fd3_context_create;
98 pscreen->is_format_supported = fd3_screen_is_format_supported;
99 fd3_emit_init_screen(pscreen);
100 ir3_screen_init(pscreen);
101
102 screen->setup_slices = fd3_setup_slices;
103 if (FD_DBG(TTILE))
104 screen->tile_mode = fd3_tile_mode;
105
106 screen->primtypes = primtypes;
107 }
108