lima: track write submits of context (v3)
[mesa.git] / src / gallium / drivers / lima / lima_format.c
1 /*
2 * Copyright (c) 2011-2013 Luc Verhaegen <libv@skynet.be>
3 * Copyright (c) 2018-2019 Lima Project
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, sub license,
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
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the 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 NON-INFRINGEMENT. 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
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26 #include <stdlib.h>
27
28 #include <util/macros.h>
29
30 #include "lima_format.h"
31
32 #define LIMA_TEXEL_FORMAT_L8 0x09
33 #define LIMA_TEXEL_FORMAT_A8 0x0a
34 #define LIMA_TEXEL_FORMAT_I8 0x0b
35 #define LIMA_TEXEL_FORMAT_BGR_565 0x0e
36 #define LIMA_TEXEL_FORMAT_L8A8 0x11
37 #define LIMA_TEXEL_FORMAT_L16 0x12
38 #define LIMA_TEXEL_FORMAT_A16 0x13
39 #define LIMA_TEXEL_FORMAT_I16 0x14
40 #define LIMA_TEXEL_FORMAT_RGB_888 0x15
41 #define LIMA_TEXEL_FORMAT_RGBA_8888 0x16
42 #define LIMA_TEXEL_FORMAT_RGBX_8888 0x17
43 #define LIMA_TEXEL_FORMAT_Z24S8 0x2c
44 #define LIMA_TEXEL_FORMAT_NONE -1
45
46 #define LIMA_PIXEL_FORMAT_B5G6R5 0x00
47 #define LIMA_PIXEL_FORMAT_B8G8R8A8 0x03
48 #define LIMA_PIXEL_FORMAT_Z16 0x0e
49 #define LIMA_PIXEL_FORMAT_Z24S8 0x0f
50 #define LIMA_PIXEL_FORMAT_NONE -1
51
52 struct lima_format {
53 bool present;
54 int texel;
55 int pixel;
56 bool swap_r_b;
57 };
58
59 #define LIMA_FORMAT(pipe, tex, pix, swap) \
60 [PIPE_FORMAT_##pipe] = { \
61 .present = true, .texel = LIMA_TEXEL_FORMAT_##tex, \
62 .pixel = LIMA_PIXEL_FORMAT_##pix, .swap_r_b = swap, \
63 }
64
65 static const struct lima_format lima_format_table[] = {
66 LIMA_FORMAT(R8G8B8A8_UNORM, RGBA_8888, B8G8R8A8, true),
67 LIMA_FORMAT(B8G8R8A8_UNORM, RGBA_8888, B8G8R8A8, false),
68 LIMA_FORMAT(R8G8B8A8_SRGB, RGBA_8888, B8G8R8A8, true),
69 LIMA_FORMAT(B8G8R8A8_SRGB, RGBA_8888, B8G8R8A8, false),
70 LIMA_FORMAT(R8G8B8X8_UNORM, RGBX_8888, B8G8R8A8, true),
71 LIMA_FORMAT(B8G8R8X8_UNORM, RGBX_8888, B8G8R8A8, false),
72 LIMA_FORMAT(B5G6R5_UNORM, BGR_565, B5G6R5, false),
73 LIMA_FORMAT(Z24_UNORM_S8_UINT, Z24S8, Z24S8, false),
74 LIMA_FORMAT(Z24X8_UNORM, Z24S8, Z24S8, false),
75 /* Blob uses L16 for Z16 */
76 LIMA_FORMAT(Z16_UNORM, L16, Z16, false),
77 LIMA_FORMAT(L16_UNORM, L16, NONE, false),
78 LIMA_FORMAT(L8_UNORM, L8, NONE, false),
79 LIMA_FORMAT(A16_UNORM, A16, NONE, false),
80 LIMA_FORMAT(A8_UNORM, A8, NONE, false),
81 LIMA_FORMAT(I16_UNORM, I16, NONE, false),
82 LIMA_FORMAT(I8_UNORM, I8, NONE, false),
83 LIMA_FORMAT(L8A8_UNORM, L8A8, NONE, false),
84 };
85
86 static const struct lima_format *
87 get_format(enum pipe_format f)
88 {
89 if (f >= ARRAY_SIZE(lima_format_table) ||
90 !lima_format_table[f].present)
91 return NULL;
92
93 return lima_format_table + f;
94 }
95
96 bool
97 lima_format_texel_supported(enum pipe_format f)
98 {
99 const struct lima_format *lf = get_format(f);
100
101 if (!lf)
102 return false;
103
104 return lf->texel != LIMA_TEXEL_FORMAT_NONE;
105 }
106
107 bool
108 lima_format_pixel_supported(enum pipe_format f)
109 {
110 const struct lima_format *lf = get_format(f);
111
112 if (!lf)
113 return false;
114
115 return lf->pixel != LIMA_PIXEL_FORMAT_NONE;
116 }
117
118 int
119 lima_format_get_texel(enum pipe_format f)
120 {
121 return lima_format_table[f].texel;
122 }
123
124 int
125 lima_format_get_pixel(enum pipe_format f)
126 {
127 return lima_format_table[f].pixel;
128 }
129
130 bool
131 lima_format_get_swap_rb(enum pipe_format f)
132 {
133 return lima_format_table[f].swap_r_b;
134 }