1 /*
2 * Copyright © 2014 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 "fd4_context.h"
13 #include "fd4_emit.h"
14 #include "fd4_format.h"
15 #include "fd4_resource.h"
16 #include "fd4_screen.h"
17
18 #include "ir3/ir3_compiler.h"
19
20 static bool
fd4_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 fd4_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 (fd4_pipe2vtx(format) != VFMT4_NONE)) {
41 retval |= PIPE_BIND_VERTEX_BUFFER;
42 }
43
44 if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
45 (fd4_pipe2tex(format) != TFMT4_NONE) &&
46 (target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) {
47 retval |= PIPE_BIND_SAMPLER_VIEW;
48 }
49
50 if ((usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
51 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)) &&
52 (fd4_pipe2color(format) != RB4_NONE) &&
53 (fd4_pipe2tex(format) != TFMT4_NONE)) {
54 retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
55 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
56 }
57
58 /* For ARB_framebuffer_no_attachments: */
59 if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
60 retval |= usage & PIPE_BIND_RENDER_TARGET;
61 }
62
63 if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
64 (fd4_pipe2depth(format) != (enum a4xx_depth_format) ~0) &&
65 (fd4_pipe2tex(format) != TFMT4_NONE)) {
66 retval |= PIPE_BIND_DEPTH_STENCIL;
67 }
68
69 if ((usage & PIPE_BIND_INDEX_BUFFER) &&
70 (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
71 retval |= PIPE_BIND_INDEX_BUFFER;
72 }
73
74 if (retval != usage) {
75 DBG("not supported: format=%s, target=%d, sample_count=%d, "
76 "usage=%x, retval=%x",
77 util_format_name(format), target, sample_count, usage, retval);
78 }
79
80 return retval == usage;
81 }
82
83 /* clang-format off */
84 static const enum pc_di_primtype primtypes[] = {
85 [MESA_PRIM_POINTS] = DI_PT_POINTLIST,
86 [MESA_PRIM_LINES] = DI_PT_LINELIST,
87 [MESA_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
88 [MESA_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
89 [MESA_PRIM_TRIANGLES] = DI_PT_TRILIST,
90 [MESA_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
91 [MESA_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
92 [MESA_PRIM_COUNT] = DI_PT_RECTLIST, /* internal clear blits */
93 };
94 /* clang-format on */
95
96 void
fd4_screen_init(struct pipe_screen * pscreen)97 fd4_screen_init(struct pipe_screen *pscreen)
98 {
99 struct fd_screen *screen = fd_screen(pscreen);
100 screen->max_rts = A4XX_MAX_RENDER_TARGETS;
101 screen->setup_slices = fd4_setup_slices;
102 pscreen->context_create = fd4_context_create;
103 pscreen->is_format_supported = fd4_screen_is_format_supported;
104 fd4_emit_init_screen(pscreen);
105 ir3_screen_init(pscreen);
106
107 screen->primtypes = primtypes;
108 }
109