1 /*
2 * Copyright © 2014-2017 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * @file v3d_formats.c
26 *
27 * Contains the table and accessors for V3D texture and render target format
28 * support.
29 *
30 * The hardware has limited support for texture formats, and extremely limited
31 * support for render target formats. As a result, we emulate other formats
32 * in our shader code, and this stores the table for doing so.
33 */
34
35 #include "util/macros.h"
36
37 #include "v3d_context.h"
38 #include "v3d_format_table.h"
39
40 /* The format internal types are the same across V3D versions */
41 #define V3D_VERSION 42
42 #include "broadcom/cle/v3dx_pack.h"
43
44 bool
v3d_rt_format_supported(const struct v3d_device_info * devinfo,enum pipe_format f)45 v3d_rt_format_supported(const struct v3d_device_info *devinfo,
46 enum pipe_format f)
47 {
48 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
49
50 if (!vf)
51 return false;
52
53 return vf->rt_type != V3D_OUTPUT_IMAGE_FORMAT_NO;
54 }
55
56 uint8_t
v3d_get_rt_format(const struct v3d_device_info * devinfo,enum pipe_format f)57 v3d_get_rt_format(const struct v3d_device_info *devinfo, enum pipe_format f)
58 {
59 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
60
61 if (!vf)
62 return 0;
63
64 return vf->rt_type;
65 }
66
67 bool
v3d_tex_format_supported(const struct v3d_device_info * devinfo,enum pipe_format f)68 v3d_tex_format_supported(const struct v3d_device_info *devinfo,
69 enum pipe_format f)
70 {
71 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
72
73 return vf != NULL;
74 }
75
76 uint8_t
v3d_get_tex_format(const struct v3d_device_info * devinfo,enum pipe_format f)77 v3d_get_tex_format(const struct v3d_device_info *devinfo, enum pipe_format f)
78 {
79 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
80
81 if (!vf)
82 return 0;
83
84 return vf->tex_type;
85 }
86
87 uint8_t
v3d_get_tex_return_size(const struct v3d_device_info * devinfo,enum pipe_format f)88 v3d_get_tex_return_size(const struct v3d_device_info *devinfo,
89 enum pipe_format f)
90 {
91 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
92
93 if (!vf)
94 return 0;
95
96 if (V3D_DBG(TMU_16BIT))
97 return 16;
98
99 if (V3D_DBG(TMU_32BIT))
100 return 32;
101
102 return vf->return_size;
103 }
104
105 uint8_t
v3d_get_tex_return_channels(const struct v3d_device_info * devinfo,enum pipe_format f)106 v3d_get_tex_return_channels(const struct v3d_device_info *devinfo,
107 enum pipe_format f)
108 {
109 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
110
111 if (!vf)
112 return 0;
113
114 return vf->return_channels;
115 }
116
117 const uint8_t *
v3d_get_format_swizzle(const struct v3d_device_info * devinfo,enum pipe_format f)118 v3d_get_format_swizzle(const struct v3d_device_info *devinfo, enum pipe_format f)
119 {
120 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
121 static const uint8_t fallback[] = {0, 1, 2, 3};
122
123 if (!vf)
124 return fallback;
125
126 return vf->swizzle;
127 }
128
129 bool
v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info * devinfo,enum pipe_format f)130 v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info *devinfo,
131 enum pipe_format f)
132 {
133 uint32_t internal_type;
134 uint32_t internal_bpp;
135
136 const struct v3d_format *vf = v3d_X(devinfo, get_format_desc)(f);
137
138 if (!vf)
139 return false;
140
141 v3d_X(devinfo, get_internal_type_bpp_for_output_format)
142 (vf->rt_type, &internal_type, &internal_bpp);
143
144 return internal_type == V3D_INTERNAL_TYPE_8 ||
145 internal_type == V3D_INTERNAL_TYPE_16F;
146 }
147