• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 33
42 #include "broadcom/cle/v3dx_pack.h"
43 
44 static const struct v3d_format *
get_format(const struct v3d_device_info * devinfo,enum pipe_format f)45 get_format(const struct v3d_device_info *devinfo, enum pipe_format f)
46 {
47         if (devinfo->ver >= 41)
48                 return v3d41_get_format_desc(f);
49         else
50                 return v3d33_get_format_desc(f);
51 }
52 
53 bool
v3d_rt_format_supported(const struct v3d_device_info * devinfo,enum pipe_format f)54 v3d_rt_format_supported(const struct v3d_device_info *devinfo,
55                         enum pipe_format f)
56 {
57         const struct v3d_format *vf = get_format(devinfo, f);
58 
59         if (!vf)
60                 return false;
61 
62         return vf->rt_type != V3D_OUTPUT_IMAGE_FORMAT_NO;
63 }
64 
65 uint8_t
v3d_get_rt_format(const struct v3d_device_info * devinfo,enum pipe_format f)66 v3d_get_rt_format(const struct v3d_device_info *devinfo, enum pipe_format f)
67 {
68         const struct v3d_format *vf = get_format(devinfo, f);
69 
70         if (!vf)
71                 return 0;
72 
73         return vf->rt_type;
74 }
75 
76 bool
v3d_tex_format_supported(const struct v3d_device_info * devinfo,enum pipe_format f)77 v3d_tex_format_supported(const struct v3d_device_info *devinfo,
78                          enum pipe_format f)
79 {
80         const struct v3d_format *vf = get_format(devinfo, f);
81 
82         return vf != NULL;
83 }
84 
85 uint8_t
v3d_get_tex_format(const struct v3d_device_info * devinfo,enum pipe_format f)86 v3d_get_tex_format(const struct v3d_device_info *devinfo, enum pipe_format f)
87 {
88         const struct v3d_format *vf = get_format(devinfo, f);
89 
90         if (!vf)
91                 return 0;
92 
93         return vf->tex_type;
94 }
95 
96 uint8_t
v3d_get_tex_return_size(const struct v3d_device_info * devinfo,enum pipe_format f,enum pipe_tex_compare compare)97 v3d_get_tex_return_size(const struct v3d_device_info *devinfo,
98                         enum pipe_format f, enum pipe_tex_compare compare)
99 {
100         const struct v3d_format *vf = get_format(devinfo, f);
101 
102         if (!vf)
103                 return 0;
104 
105         if (unlikely(V3D_DEBUG & V3D_DEBUG_TMU_16BIT))
106                 return 16;
107 
108         if (unlikely(V3D_DEBUG & V3D_DEBUG_TMU_32BIT))
109                 return 32;
110 
111         if (compare == PIPE_TEX_COMPARE_R_TO_TEXTURE)
112                 return 16;
113 
114         return vf->return_size;
115 }
116 
117 uint8_t
v3d_get_tex_return_channels(const struct v3d_device_info * devinfo,enum pipe_format f)118 v3d_get_tex_return_channels(const struct v3d_device_info *devinfo,
119                             enum pipe_format f)
120 {
121         const struct v3d_format *vf = get_format(devinfo, f);
122 
123         if (!vf)
124                 return 0;
125 
126         return vf->return_channels;
127 }
128 
129 const uint8_t *
v3d_get_format_swizzle(const struct v3d_device_info * devinfo,enum pipe_format f)130 v3d_get_format_swizzle(const struct v3d_device_info *devinfo, enum pipe_format f)
131 {
132         const struct v3d_format *vf = get_format(devinfo, f);
133         static const uint8_t fallback[] = {0, 1, 2, 3};
134 
135         if (!vf)
136                 return fallback;
137 
138         return vf->swizzle;
139 }
140 
141 void
v3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info * devinfo,uint32_t format,uint32_t * type,uint32_t * bpp)142 v3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info *devinfo,
143                                             uint32_t format,
144                                             uint32_t *type,
145                                             uint32_t *bpp)
146 {
147         if (devinfo->ver >= 41) {
148                 return v3d41_get_internal_type_bpp_for_output_format(format,
149                                                                      type, bpp);
150         } else {
151                 return v3d33_get_internal_type_bpp_for_output_format(format,
152                                                                      type, bpp);
153         }
154 }
155 
156 bool
v3d_tfu_supports_tex_format(const struct v3d_device_info * devinfo,uint32_t tex_format,bool for_mipmap)157 v3d_tfu_supports_tex_format(const struct v3d_device_info *devinfo,
158                             uint32_t tex_format,
159                             bool for_mipmap)
160 {
161         if (devinfo->ver >= 41) {
162                 return v3d41_tfu_supports_tex_format(tex_format, for_mipmap);
163         } else {
164                 return v3d33_tfu_supports_tex_format(tex_format, for_mipmap);
165         }
166 }
167 
168 bool
v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info * devinfo,enum pipe_format f)169 v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info *devinfo,
170                                      enum pipe_format f)
171 {
172         uint32_t internal_type;
173         uint32_t internal_bpp;
174 
175         const struct v3d_format *vf = get_format(devinfo, f);
176 
177         if (!vf)
178                 return false;
179 
180         v3d_get_internal_type_bpp_for_output_format(devinfo,
181                                                     vf->rt_type,
182                                                     &internal_type,
183                                                     &internal_bpp);
184 
185         return internal_type == V3D_INTERNAL_TYPE_8 ||
186                internal_type == V3D_INTERNAL_TYPE_16F;
187 }
188