xref: /aosp_15_r20/external/mesa3d/src/imagination/vulkan/pvr_job_common.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2022 Imagination Technologies Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * 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 THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef PVR_JOB_COMMON_H
25 #define PVR_JOB_COMMON_H
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan.h>
30 
31 #include "hwdef/rogue_hw_defs.h"
32 #include "pvr_csb_enum_helpers.h"
33 #include "pvr_private.h"
34 #include "pvr_types.h"
35 
36 enum pvr_pbe_gamma {
37    PVR_PBE_GAMMA_NONE,
38    /* For two-channel pack formats. */
39    PVR_PBE_GAMMA_RED,
40    PVR_PBE_GAMMA_REDGREEN,
41    /* For all other pack formats. */
42    PVR_PBE_GAMMA_ENABLED,
43 };
44 
45 /**
46  * These are parameters specific to the surface being set up and hence can be
47  * typically set up at surface creation time.
48  */
49 struct pvr_pbe_surf_params {
50    /* Swizzle for a format can be retrieved using pvr_get_format_swizzle(). */
51    uint8_t swizzle[4];
52    /* is_normalized can be retrieved using pvr_vk_format_is_fully_normalized(). */
53    bool is_normalized;
54    /* pbe_packmode can be retrieved using pvr_get_pbe_packmode(). */
55    uint32_t pbe_packmode;
56    /* source_format and gamma can be retrieved using
57     * pvr_pbe_get_src_format_and_gamma().
58     */
59    uint32_t source_format;
60    enum pvr_pbe_gamma gamma;
61    /* nr_components can be retrieved using vk_format_get_nr_components(). */
62    uint32_t nr_components;
63 
64    /* When an RT of MRT is packed using less USC outputs, this flag needs to be
65     * setup to true.
66     *
67     * Currently, this flag is only considered when has_usc_f16_sop is enabled.
68     * And it needs to be true when a render target by default should use F16
69     * USC channel but uses U8 channel instead for squeezing into on-chip MRT.
70     *
71     * It is better to make this member with FF_ACCUMFORMAT type or, at least,
72     * describe USC channel size. But for now, only use this flag for
73     * simplicity.
74     */
75 
76    pvr_dev_addr_t addr;
77    enum pvr_memlayout mem_layout;
78    uint32_t stride;
79 
80    /* Depth size for renders */
81    uint32_t depth;
82 
83    /* Pre-rotation dimensions of surface */
84    uint32_t width;
85    uint32_t height;
86 
87    bool z_only_render;
88    bool down_scale;
89 };
90 
91 /**
92  * These parameters are generally render-specific and need to be set up at the
93  * time #pvr_pbe_pack_state() is called.
94  */
95 struct pvr_pbe_render_params {
96    /* Clipping params are in terms of pixels and are inclusive. */
97    uint32_t min_x_clip;
98    uint32_t max_x_clip;
99 
100    uint32_t min_y_clip;
101    uint32_t max_y_clip;
102 
103    /* Start position of pixels to be read within 128bit USC output buffer. */
104    enum pvr_pbe_source_start_pos source_start;
105 
106    /* 9-bit slice number to be used when memlayout is 3D twiddle. */
107    uint32_t slice;
108 
109    /* Index */
110    uint32_t mrt_index;
111 };
112 
113 void pvr_pbe_pack_state(
114    const struct pvr_device_info *dev_info,
115    const struct pvr_pbe_surf_params *surface_params,
116    const struct pvr_pbe_render_params *render_params,
117    uint32_t pbe_cs_words[static const ROGUE_NUM_PBESTATE_STATE_WORDS],
118    uint64_t pbe_reg_words[static const ROGUE_NUM_PBESTATE_REG_WORDS]);
119 
120 /* Helper to calculate pvr_pbe_surf_params::gamma and
121  * pvr_pbe_surf_params::source_format.
122  */
123 void pvr_pbe_get_src_format_and_gamma(VkFormat vk_format,
124                                       enum pvr_pbe_gamma default_gamma,
125                                       bool with_packed_usc_channel,
126                                       uint32_t *const src_format_out,
127                                       enum pvr_pbe_gamma *const gamma_out);
128 
129 void pvr_setup_tiles_in_flight(
130    const struct pvr_device_info *dev_info,
131    const struct pvr_device_runtime_info *dev_runtime_info,
132    uint32_t msaa_mode,
133    uint32_t pixel_width,
134    bool paired_tiles,
135    uint32_t max_tiles_in_flight,
136    uint32_t *const isp_ctl_out,
137    uint32_t *const pixel_ctl_out);
138 
139 #endif /* PVR_JOB_COMMON_H */
140