| 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 "fd2_context.h" |
| 13 |
#include "fd2_emit.h" |
| 14 |
#include "fd2_resource.h" |
| 15 |
#include "fd2_screen.h" |
| 16 |
#include "fd2_util.h" |
| 17 |
|
| 18 |
static bool |
| 19 |
fd2_screen_is_format_supported(struct pipe_screen *pscreen, |
| 20 |
enum pipe_format format, |
| 21 |
enum pipe_texture_target target, |
| 22 |
unsigned sample_count, |
| 23 |
unsigned storage_sample_count, unsigned usage) |
| 24 |
{ |
| 25 |
unsigned retval = 0; |
| 26 |
|
| 27 |
if ((target >= PIPE_MAX_TEXTURE_TYPES) || |
| 28 |
(sample_count > 1)) { /* TODO add MSAA */ |
| 29 |
DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x", |
| 30 |
util_format_name(format), target, sample_count, usage); |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) |
| 35 |
return false; |
| 36 |
|
| 37 |
if ((usage & PIPE_BIND_RENDER_TARGET) && |
| 38 |
fd2_pipe2color(format) != (enum a2xx_colorformatx) ~0) { |
| 39 |
retval |= PIPE_BIND_RENDER_TARGET; |
| 40 |
} |
| 41 |
|
| 42 |
if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_VERTEX_BUFFER)) && |
| 43 |
!util_format_is_srgb(format) && !util_format_is_pure_integer(format) && |
| 44 |
fd2_pipe2surface(format).format != FMT_INVALID) { |
| 45 |
retval |= usage & PIPE_BIND_VERTEX_BUFFER; |
| 46 |
/* the only npot blocksize supported texture format is R32G32B32_FLOAT */ |
| 47 |
if (util_is_power_of_two_or_zero(util_format_get_blocksize(format)) || |
| 48 |
format == PIPE_FORMAT_R32G32B32_FLOAT) |
| 49 |
retval |= usage & PIPE_BIND_SAMPLER_VIEW; |
| 50 |
} |
| 51 |
|
| 52 |
if ((usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | |
| 53 |
PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)) && |
| 54 |
(fd2_pipe2color(format) != (enum a2xx_colorformatx) ~0)) { |
| 55 |
retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | |
| 56 |
PIPE_BIND_SCANOUT | PIPE_BIND_SHARED); |
| 57 |
} |
| 58 |
|
| 59 |
if ((usage & PIPE_BIND_DEPTH_STENCIL) && |
| 60 |
(fd_pipe2depth(format) != (enum adreno_rb_depth_format) ~0)) { |
| 61 |
retval |= PIPE_BIND_DEPTH_STENCIL; |
| 62 |
} |
| 63 |
|
| 64 |
if ((usage & PIPE_BIND_INDEX_BUFFER) && |
| 65 |
(fd_pipe2index(format) != (enum pc_di_index_size) ~0)) { |
| 66 |
retval |= PIPE_BIND_INDEX_BUFFER; |
| 67 |
} |
| 68 |
|
| 69 |
if (retval != usage) { |
| 70 |
DBG("not supported: format=%s, target=%d, sample_count=%d, " |
| 71 |
"usage=%x, retval=%x", |
| 72 |
util_format_name(format), target, sample_count, usage, retval); |
| 73 |
} |
| 74 |
|
| 75 |
return retval == usage; |
| 76 |
} |
| 77 |
|
| 78 |
/* clang-format off */ |
| 79 |
static const enum pc_di_primtype a22x_primtypes[MESA_PRIM_COUNT] = { |
| 80 |
[MESA_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE, |
| 81 |
[MESA_PRIM_LINES] = DI_PT_LINELIST, |
| 82 |
[MESA_PRIM_LINE_STRIP] = DI_PT_LINESTRIP, |
| 83 |
[MESA_PRIM_LINE_LOOP] = DI_PT_LINELOOP, |
| 84 |
[MESA_PRIM_TRIANGLES] = DI_PT_TRILIST, |
| 85 |
[MESA_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP, |
| 86 |
[MESA_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN, |
| 87 |
}; |
| 88 |
|
| 89 |
static const enum pc_di_primtype a20x_primtypes[MESA_PRIM_COUNT] = { |
| 90 |
[MESA_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE, |
| 91 |
[MESA_PRIM_LINES] = DI_PT_LINELIST, |
| 92 |
[MESA_PRIM_LINE_STRIP] = DI_PT_LINESTRIP, |
| 93 |
[MESA_PRIM_TRIANGLES] = DI_PT_TRILIST, |
| 94 |
[MESA_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP, |
| 95 |
[MESA_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN, |
| 96 |
}; |
| 97 |
/* clang-format on */ |
| 98 |
|
| 99 |
void |
| 100 |
fd2_screen_init(struct pipe_screen *pscreen) |
| 101 |
{ |
| 102 |
struct fd_screen *screen = fd_screen(pscreen); |
| 103 |
|
| 104 |
screen->max_rts = 1; |
| 105 |
pscreen->context_create = fd2_context_create; |
| 106 |
pscreen->is_format_supported = fd2_screen_is_format_supported; |
| 107 |
|
| 108 |
screen->layout_resource = fd2_layout_resource; |
| 109 |
if (FD_DBG(TTILE)) |
| 110 |
screen->tile_mode = fd2_tile_mode; |
| 111 |
|
| 112 |
fd2_emit_init_screen(pscreen); |
| 113 |
|
| 114 |
if (screen->gpu_id >= 220) { |
| 115 |
screen->primtypes = a22x_primtypes; |
| 116 |
} else { |
| 117 |
screen->primtypes = a20x_primtypes; |
| 118 |
} |
| 119 |
} |