xref: /aosp_15_r20/external/mesa3d/src/imagination/vulkan/pvr_spm.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2023 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_SPM_H
25 #define PVR_SPM_H
26 
27 /**
28  * \file pvr_spm.h
29  *
30  * \brief Smart Parameter Management.
31  *
32  * With large amounts of geometry the device can run out of Parameter Buffer
33  * (PB) as no more free pages are left in the freelist to allow the PB to grow.
34  * In such cases the render is split into multiple partial renders (PRs) to fit
35  * within the memory constraints. Each PR produces intermediary results until
36  * they have all completed, producing the final scene equivalent to what would
37  * have been produced by the original render.
38  *
39  * SPM comprises all the necessary work required of the driver to manage the PB.
40  */
41 
42 #include <stdint.h>
43 #include <vulkan/vulkan_core.h>
44 
45 #include "hwdef/rogue_hw_defs.h"
46 #include "pvr_limits.h"
47 #include "util/simple_mtx.h"
48 
49 struct pvr_bo;
50 struct pvr_device;
51 struct pvr_framebuffer;
52 struct pvr_render_pass;
53 struct pvr_renderpass_hwsetup_render;
54 struct pvr_spm_scratch_buffer;
55 
56 struct pvr_spm_scratch_buffer_store {
57    simple_mtx_t mtx;
58    struct pvr_spm_scratch_buffer *head_ref;
59 };
60 
61 struct pvr_spm_eot_state {
62    uint64_t pbe_reg_words[PVR_MAX_COLOR_ATTACHMENTS]
63                          [ROGUE_NUM_PBESTATE_REG_WORDS];
64 
65    struct pvr_suballoc_bo *usc_eot_program;
66 
67    /* TODO: Make this struct pvr_pds_upload? It would pull in pvr_private.h
68     * though which causes a cycle since that includes pvr_spm.h .
69     */
70    /* This is only the data section upload. The code was uploaded at device
71     * creation.
72     */
73    uint64_t pixel_event_program_data_offset;
74    struct pvr_suballoc_bo *pixel_event_program_data_upload;
75 };
76 
77 struct pvr_spm_bgobj_state {
78    struct pvr_bo *consts_buffer;
79 
80    /* TODO: Make this struct pvr_pds_upload? It would pull in pvr_private.h
81     * though which causes a cycle since that includes pvr_spm.h .
82     */
83    struct pvr_suballoc_bo *pds_texture_data_upload;
84 
85    uint64_t pds_reg_values[ROGUE_NUM_CR_PDS_BGRND_WORDS];
86 };
87 
88 void pvr_spm_init_scratch_buffer_store(struct pvr_device *device);
89 void pvr_spm_finish_scratch_buffer_store(struct pvr_device *device);
90 
91 /* A scratch buffer is required in various situations:
92  *
93  *  - An MSAA workload which needs saving to a larger buffer than the output for
94  *    PRs.
95  *  - To store transient results during a PR with read only attachments (i.e.
96  *    VK_ATTACHMENT_STORE_OP_NONE, not currently supported) or lazily allocated
97  *    attachments with no backing.
98  */
99 uint64_t
100 pvr_spm_scratch_buffer_calc_required_size(const struct pvr_render_pass *pass,
101                                           uint32_t framebuffer_width,
102                                           uint32_t framebuffer_height);
103 VkResult pvr_spm_scratch_buffer_get_buffer(
104    struct pvr_device *device,
105    uint64_t size,
106    struct pvr_spm_scratch_buffer **const buffer_out);
107 void pvr_spm_scratch_buffer_release(struct pvr_device *device,
108                                     struct pvr_spm_scratch_buffer *buffer);
109 
110 /* The SPM load programs are needed for the SPM background object load op. */
111 VkResult pvr_device_init_spm_load_state(struct pvr_device *device);
112 void pvr_device_finish_spm_load_state(struct pvr_device *device);
113 
114 VkResult
115 pvr_spm_init_eot_state(struct pvr_device *device,
116                        struct pvr_spm_eot_state *spm_eot_state,
117                        const struct pvr_framebuffer *framebuffer,
118                        const struct pvr_renderpass_hwsetup_render *hw_render,
119                        uint32_t *emit_count_out);
120 void pvr_spm_finish_eot_state(struct pvr_device *device,
121                               struct pvr_spm_eot_state *spm_eot_state);
122 
123 VkResult
124 pvr_spm_init_bgobj_state(struct pvr_device *device,
125                          struct pvr_spm_bgobj_state *spm_bgobj_state,
126                          const struct pvr_framebuffer *framebuffer,
127                          const struct pvr_renderpass_hwsetup_render *hw_render,
128                          uint32_t emit_count);
129 void pvr_spm_finish_bgobj_state(struct pvr_device *device,
130                                 struct pvr_spm_bgobj_state *spm_bgobj_state);
131 
132 #endif /* PVR_SPM_H */
133