Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/v3d/v3d_formats.c
4570 views
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 *
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
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
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
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
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
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 (compare == PIPE_TEX_COMPARE_R_TO_TEXTURE)
106
return 16;
107
108
return vf->return_size;
109
}
110
111
uint8_t
112
v3d_get_tex_return_channels(const struct v3d_device_info *devinfo,
113
enum pipe_format f)
114
{
115
const struct v3d_format *vf = get_format(devinfo, f);
116
117
if (!vf)
118
return 0;
119
120
return vf->return_channels;
121
}
122
123
const uint8_t *
124
v3d_get_format_swizzle(const struct v3d_device_info *devinfo, enum pipe_format f)
125
{
126
const struct v3d_format *vf = get_format(devinfo, f);
127
static const uint8_t fallback[] = {0, 1, 2, 3};
128
129
if (!vf)
130
return fallback;
131
132
return vf->swizzle;
133
}
134
135
void
136
v3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info *devinfo,
137
uint32_t format,
138
uint32_t *type,
139
uint32_t *bpp)
140
{
141
if (devinfo->ver >= 41) {
142
return v3d41_get_internal_type_bpp_for_output_format(format,
143
type, bpp);
144
} else {
145
return v3d33_get_internal_type_bpp_for_output_format(format,
146
type, bpp);
147
}
148
}
149
150
bool
151
v3d_tfu_supports_tex_format(const struct v3d_device_info *devinfo,
152
uint32_t tex_format,
153
bool for_mipmap)
154
{
155
if (devinfo->ver >= 41) {
156
return v3d41_tfu_supports_tex_format(tex_format, for_mipmap);
157
} else {
158
return v3d33_tfu_supports_tex_format(tex_format, for_mipmap);
159
}
160
}
161
162
bool
163
v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info *devinfo,
164
enum pipe_format f)
165
{
166
uint32_t internal_type;
167
uint32_t internal_bpp;
168
169
const struct v3d_format *vf = get_format(devinfo, f);
170
171
if (!vf)
172
return false;
173
174
v3d_get_internal_type_bpp_for_output_format(devinfo,
175
vf->rt_type,
176
&internal_type,
177
&internal_bpp);
178
179
return internal_type == V3D_INTERNAL_TYPE_8 ||
180
internal_type == V3D_INTERNAL_TYPE_16F;
181
}
182
183