xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/svga/svga_format.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 2011-2024 Broadcom. All Rights Reserved.
3  * The term “Broadcom” refers to Broadcom Inc.
4  * and/or its subsidiaries.
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #ifndef SVGA_FORMAT_H_
9 #define SVGA_FORMAT_H_
10 
11 
12 #include "util/format/u_formats.h"
13 #include "svga_context.h"
14 #include "svga_types.h"
15 #include "svga_reg.h"
16 #include "svga3d_reg.h"
17 
18 
19 struct svga_screen;
20 
21 
22 /**
23  * Vertex format flags.  These are used to specify that some vertex formats
24  * need extra processing/conversion in the vertex shader.  For example,
25  * setting the W component to 1, or swapping R/B, or converting packed uint
26  * types to signed int/snorm.
27  */
28 #define VF_ADJUST_RANGE     (1 << 0)
29 #define VF_W_TO_1           (1 << 1)
30 #define VF_U_TO_F_CAST      (1 << 2)  /* convert uint to float */
31 #define VF_I_TO_F_CAST      (1 << 3)  /* convert sint to float */
32 #define VF_BGRA             (1 << 4)  /* swap R/B */
33 #define VF_PUINT_TO_SNORM   (1 << 5)  /* 10_10_10_2 to snorm */
34 #define VF_PUINT_TO_USCALED (1 << 6)  /* 10_10_10_2 to uscaled */
35 #define VF_PUINT_TO_SSCALED (1 << 7)  /* 10_10_10_2 to sscaled */
36 
37 /**
38  * Texture format flags.
39  */
40 #define TF_GEN_MIPS         (1 << 8)  /* supports hw generate mipmap */
41 #define TF_000X             (1 << 9)  /* swizzle <0, 0, 0, X> */
42 #define TF_XXXX             (1 << 10) /* swizzle <X, X, X, X> */
43 #define TF_XXX1             (1 << 11) /* swizzle <X, X, X, 1> */
44 #define TF_XXXY             (1 << 12) /* swizzle <X, X, X, Y> */
45 #define TF_UAV              (1 << 13) /* supports uav */
46 #define TF_SM5              (1 << 14) /* supported in SM5 */
47 
48 void
49 svga_translate_vertex_format_vgpu10(enum pipe_format format,
50                                     SVGA3dSurfaceFormat *svga_format,
51                                     unsigned *vf_flags);
52 
53 void
54 svga_translate_texture_buffer_view_format(enum pipe_format format,
55                                           SVGA3dSurfaceFormat *svga_format,
56                                           unsigned *tf_flags);
57 
58 enum SVGA3dSurfaceFormat
59 svga_translate_format(const struct svga_screen *ss,
60                       enum pipe_format format,
61                       unsigned bind);
62 
63 void
64 svga_get_format_cap(struct svga_screen *ss,
65                     SVGA3dSurfaceFormat format,
66                     SVGA3dSurfaceFormatCaps *caps);
67 
68 void
69 svga_format_size(SVGA3dSurfaceFormat format,
70                  unsigned *block_width,
71                  unsigned *block_height,
72                  unsigned *bytes_per_block);
73 
74 const char *
75 svga_format_name(SVGA3dSurfaceFormat format);
76 
77 bool
78 svga_format_is_integer(SVGA3dSurfaceFormat format);
79 
80 bool
81 svga_format_support_gen_mips(enum pipe_format format);
82 
83 enum tgsi_return_type
84 svga_get_texture_datatype(enum pipe_format format);
85 
86 
87 // XXX: Move this to svga_context?
88 bool
89 svga_has_any_integer_cbufs(const struct svga_context *svga);
90 
91 
92 SVGA3dSurfaceFormat
93 svga_typeless_format(SVGA3dSurfaceFormat format);
94 
95 
96 SVGA3dSurfaceFormat
97 svga_sampler_format(SVGA3dSurfaceFormat format);
98 
99 
100 bool
101 svga_format_is_uncompressed_snorm(SVGA3dSurfaceFormat format);
102 
103 
104 bool
105 svga_format_is_typeless(SVGA3dSurfaceFormat format);
106 
107 bool
108 svga_format_is_shareable(const struct svga_screen *ss,
109                          enum pipe_format pformat,
110                          SVGA3dSurfaceFormat sformat,
111                          unsigned bind,
112                          bool verbose);
113 
114 SVGA3dSurfaceFormat
115 svga_linear_to_srgb(SVGA3dSurfaceFormat format);
116 
117 
118 bool
119 svga_is_format_supported(struct pipe_screen *screen,
120                          enum pipe_format format,
121                          enum pipe_texture_target target,
122                          unsigned sample_count,
123                          unsigned storage_sample_count,
124                          unsigned bindings);
125 
126 
127 bool
128 svga_is_dx_format_supported(struct pipe_screen *screen,
129                             enum pipe_format format,
130                             enum pipe_texture_target target,
131                             unsigned sample_count,
132                             unsigned storage_sample_count,
133                             unsigned bindings);
134 
135 #endif /* SVGA_FORMAT_H_ */
136