1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "pipe/p_screen.h"
28bf215546Sopenharmony_ci#include "util/format/u_format.h"
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "fd4_context.h"
31bf215546Sopenharmony_ci#include "fd4_emit.h"
32bf215546Sopenharmony_ci#include "fd4_format.h"
33bf215546Sopenharmony_ci#include "fd4_resource.h"
34bf215546Sopenharmony_ci#include "fd4_screen.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "ir3/ir3_compiler.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistatic bool
39bf215546Sopenharmony_cifd4_screen_is_format_supported(struct pipe_screen *pscreen,
40bf215546Sopenharmony_ci                               enum pipe_format format,
41bf215546Sopenharmony_ci                               enum pipe_texture_target target,
42bf215546Sopenharmony_ci                               unsigned sample_count,
43bf215546Sopenharmony_ci                               unsigned storage_sample_count, unsigned usage)
44bf215546Sopenharmony_ci{
45bf215546Sopenharmony_ci   unsigned retval = 0;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci   if ((target >= PIPE_MAX_TEXTURE_TYPES) ||
48bf215546Sopenharmony_ci       (sample_count > 1)) { /* TODO add MSAA */
49bf215546Sopenharmony_ci      DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",
50bf215546Sopenharmony_ci          util_format_name(format), target, sample_count, usage);
51bf215546Sopenharmony_ci      return false;
52bf215546Sopenharmony_ci   }
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci   if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
55bf215546Sopenharmony_ci      return false;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
58bf215546Sopenharmony_ci       (fd4_pipe2vtx(format) != VFMT4_NONE)) {
59bf215546Sopenharmony_ci      retval |= PIPE_BIND_VERTEX_BUFFER;
60bf215546Sopenharmony_ci   }
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
63bf215546Sopenharmony_ci       (fd4_pipe2tex(format) != TFMT4_NONE) &&
64bf215546Sopenharmony_ci       (target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) {
65bf215546Sopenharmony_ci      retval |= PIPE_BIND_SAMPLER_VIEW;
66bf215546Sopenharmony_ci   }
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   if ((usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
69bf215546Sopenharmony_ci                 PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)) &&
70bf215546Sopenharmony_ci       (fd4_pipe2color(format) != RB4_NONE) &&
71bf215546Sopenharmony_ci       (fd4_pipe2tex(format) != TFMT4_NONE)) {
72bf215546Sopenharmony_ci      retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |
73bf215546Sopenharmony_ci                         PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
74bf215546Sopenharmony_ci   }
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   /* For ARB_framebuffer_no_attachments: */
77bf215546Sopenharmony_ci   if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {
78bf215546Sopenharmony_ci      retval |= usage & PIPE_BIND_RENDER_TARGET;
79bf215546Sopenharmony_ci   }
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
82bf215546Sopenharmony_ci       (fd4_pipe2depth(format) != (enum a4xx_depth_format) ~0) &&
83bf215546Sopenharmony_ci       (fd4_pipe2tex(format) != TFMT4_NONE)) {
84bf215546Sopenharmony_ci      retval |= PIPE_BIND_DEPTH_STENCIL;
85bf215546Sopenharmony_ci   }
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   if ((usage & PIPE_BIND_INDEX_BUFFER) &&
88bf215546Sopenharmony_ci       (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {
89bf215546Sopenharmony_ci      retval |= PIPE_BIND_INDEX_BUFFER;
90bf215546Sopenharmony_ci   }
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   if (retval != usage) {
93bf215546Sopenharmony_ci      DBG("not supported: format=%s, target=%d, sample_count=%d, "
94bf215546Sopenharmony_ci          "usage=%x, retval=%x",
95bf215546Sopenharmony_ci          util_format_name(format), target, sample_count, usage, retval);
96bf215546Sopenharmony_ci   }
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci   return retval == usage;
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci/* clang-format off */
102bf215546Sopenharmony_cistatic const enum pc_di_primtype primtypes[] = {
103bf215546Sopenharmony_ci   [PIPE_PRIM_POINTS]         = DI_PT_POINTLIST,
104bf215546Sopenharmony_ci   [PIPE_PRIM_LINES]          = DI_PT_LINELIST,
105bf215546Sopenharmony_ci   [PIPE_PRIM_LINE_STRIP]     = DI_PT_LINESTRIP,
106bf215546Sopenharmony_ci   [PIPE_PRIM_LINE_LOOP]      = DI_PT_LINELOOP,
107bf215546Sopenharmony_ci   [PIPE_PRIM_TRIANGLES]      = DI_PT_TRILIST,
108bf215546Sopenharmony_ci   [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
109bf215546Sopenharmony_ci   [PIPE_PRIM_TRIANGLE_FAN]   = DI_PT_TRIFAN,
110bf215546Sopenharmony_ci   [PIPE_PRIM_MAX]            = DI_PT_RECTLIST,  /* internal clear blits */
111bf215546Sopenharmony_ci};
112bf215546Sopenharmony_ci/* clang-format on */
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_civoid
115bf215546Sopenharmony_cifd4_screen_init(struct pipe_screen *pscreen)
116bf215546Sopenharmony_ci{
117bf215546Sopenharmony_ci   struct fd_screen *screen = fd_screen(pscreen);
118bf215546Sopenharmony_ci   screen->max_rts = A4XX_MAX_RENDER_TARGETS;
119bf215546Sopenharmony_ci   screen->setup_slices = fd4_setup_slices;
120bf215546Sopenharmony_ci   pscreen->context_create = fd4_context_create;
121bf215546Sopenharmony_ci   pscreen->is_format_supported = fd4_screen_is_format_supported;
122bf215546Sopenharmony_ci   fd4_emit_init_screen(pscreen);
123bf215546Sopenharmony_ci   ir3_screen_init(pscreen);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci   screen->primtypes = primtypes;
126bf215546Sopenharmony_ci}
127