• 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 vc5_formats.c
26  *
27  * Contains the table and accessors for VC5 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 "vc5_context.h"
38 #include "vc5_format_table.h"
39 
40 static const struct vc5_format *
get_format(const struct v3d_device_info * devinfo,enum pipe_format f)41 get_format(const struct v3d_device_info *devinfo, enum pipe_format f)
42 {
43         if (devinfo->ver >= 41)
44                 return v3d41_get_format_desc(f);
45         else
46                 return v3d33_get_format_desc(f);
47 }
48 
49 bool
vc5_rt_format_supported(const struct v3d_device_info * devinfo,enum pipe_format f)50 vc5_rt_format_supported(const struct v3d_device_info *devinfo,
51                         enum pipe_format f)
52 {
53         const struct vc5_format *vf = get_format(devinfo, f);
54 
55         if (!vf)
56                 return false;
57 
58         return vf->rt_type != V3D_OUTPUT_IMAGE_FORMAT_NO;
59 }
60 
61 uint8_t
vc5_get_rt_format(const struct v3d_device_info * devinfo,enum pipe_format f)62 vc5_get_rt_format(const struct v3d_device_info *devinfo, enum pipe_format f)
63 {
64         const struct vc5_format *vf = get_format(devinfo, f);
65 
66         if (!vf)
67                 return 0;
68 
69         return vf->rt_type;
70 }
71 
72 bool
vc5_tex_format_supported(const struct v3d_device_info * devinfo,enum pipe_format f)73 vc5_tex_format_supported(const struct v3d_device_info *devinfo,
74                          enum pipe_format f)
75 {
76         const struct vc5_format *vf = get_format(devinfo, f);
77 
78         return vf != NULL;
79 }
80 
81 uint8_t
vc5_get_tex_format(const struct v3d_device_info * devinfo,enum pipe_format f)82 vc5_get_tex_format(const struct v3d_device_info *devinfo, enum pipe_format f)
83 {
84         const struct vc5_format *vf = get_format(devinfo, f);
85 
86         if (!vf)
87                 return 0;
88 
89         return vf->tex_type;
90 }
91 
92 uint8_t
vc5_get_tex_return_size(const struct v3d_device_info * devinfo,enum pipe_format f,enum pipe_tex_compare compare)93 vc5_get_tex_return_size(const struct v3d_device_info *devinfo,
94                         enum pipe_format f, enum pipe_tex_compare compare)
95 {
96         const struct vc5_format *vf = get_format(devinfo, f);
97 
98         if (!vf)
99                 return 0;
100 
101         if (compare == PIPE_TEX_COMPARE_R_TO_TEXTURE)
102                 return 16;
103 
104         return vf->return_size;
105 }
106 
107 uint8_t
vc5_get_tex_return_channels(const struct v3d_device_info * devinfo,enum pipe_format f)108 vc5_get_tex_return_channels(const struct v3d_device_info *devinfo,
109                             enum pipe_format f)
110 {
111         const struct vc5_format *vf = get_format(devinfo, f);
112 
113         if (!vf)
114                 return 0;
115 
116         return vf->return_channels;
117 }
118 
119 const uint8_t *
vc5_get_format_swizzle(const struct v3d_device_info * devinfo,enum pipe_format f)120 vc5_get_format_swizzle(const struct v3d_device_info *devinfo, enum pipe_format f)
121 {
122         const struct vc5_format *vf = get_format(devinfo, f);
123         static const uint8_t fallback[] = {0, 1, 2, 3};
124 
125         if (!vf)
126                 return fallback;
127 
128         return vf->swizzle;
129 }
130 
131 void
vc5_get_internal_type_bpp_for_output_format(const struct v3d_device_info * devinfo,uint32_t format,uint32_t * type,uint32_t * bpp)132 vc5_get_internal_type_bpp_for_output_format(const struct v3d_device_info *devinfo,
133                                             uint32_t format,
134                                             uint32_t *type,
135                                             uint32_t *bpp)
136 {
137         if (devinfo->ver >= 41) {
138                 return v3d41_get_internal_type_bpp_for_output_format(format,
139                                                                      type, bpp);
140         } else {
141                 return v3d33_get_internal_type_bpp_for_output_format(format,
142                                                                      type, bpp);
143         }
144 }
145