Debian Codegraph @

src/imagination/vulkan/pvr_spm.h

raw
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 "pvr_macros.h"
48 #include "util/simple_mtx.h"
49
50 struct pvr_bo;
51 struct pvr_device;
52 struct pvr_framebuffer;
53 struct pvr_render_pass;
54 struct pvr_renderpass_hwsetup_render;
55 struct pvr_render_state;
56 struct pvr_spm_scratch_buffer;
57
58 struct pvr_spm_scratch_buffer_store {
59 simple_mtx_t mtx;
60 struct pvr_spm_scratch_buffer *head_ref;
61 };
62
63 struct pvr_spm_eot_state {
64 uint64_t pbe_reg_words[PVR_MAX_COLOR_ATTACHMENTS]
65 [ROGUE_NUM_PBESTATE_REG_WORDS];
66
67 struct pvr_suballoc_bo *usc_eot_program;
68
69 /* TODO: Make this struct pvr_pds_upload? */
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? */
81 struct pvr_suballoc_bo *pds_texture_data_upload;
82
83 uint64_t pds_reg_values[ROGUE_NUM_CR_PDS_BGRND_WORDS];
84 };
85
86 void pvr_spm_init_scratch_buffer_store(struct pvr_device *device);
87 void pvr_spm_finish_scratch_buffer_store(struct pvr_device *device);
88
89 VkResult pvr_spm_scratch_buffer_get_buffer(
90 struct pvr_device *device,
91 uint64_t size,
92 struct pvr_spm_scratch_buffer **const buffer_out);
93 void pvr_spm_scratch_buffer_release(struct pvr_device *device,
94 struct pvr_spm_scratch_buffer *buffer);
95
96 void pvr_spm_finish_eot_state(struct pvr_device *device,
97 struct pvr_spm_eot_state *spm_eot_state);
98
99 void pvr_spm_finish_bgobj_state(struct pvr_device *device,
100 struct pvr_spm_bgobj_state *spm_bgobj_state);
101
102 #ifdef PVR_PER_ARCH
103
104 /* A scratch buffer is required in various situations:
105 *
106 * - An MSAA workload which needs saving to a larger buffer than the output for
107 * PRs.
108 * - To store transient results during a PR with read only attachments (i.e.
109 * VK_ATTACHMENT_STORE_OP_NONE, not currently supported) or lazily allocated
110 * attachments with no backing.
111 */
112 uint64_t PVR_PER_ARCH(spm_scratch_buffer_calc_required_size)(
113 const struct pvr_renderpass_hwsetup_render *renders,
114 uint32_t render_count,
115 uint32_t sample_count,
116 uint32_t framebuffer_width,
117 uint32_t framebuffer_height);
118
119 # define pvr_arch_spm_scratch_buffer_calc_required_size \
120 PVR_PER_ARCH(spm_scratch_buffer_calc_required_size)
121
122 /* The SPM load programs are needed for the SPM background object load op. */
123 VkResult PVR_PER_ARCH(device_init_spm_load_state)(struct pvr_device *device);
124
125 # define pvr_arch_device_init_spm_load_state \
126 PVR_PER_ARCH(device_init_spm_load_state)
127
128 void PVR_PER_ARCH(device_finish_spm_load_state)(struct pvr_device *device);
129
130 # define pvr_arch_device_finish_spm_load_state \
131 PVR_PER_ARCH(device_finish_spm_load_state)
132
133 VkResult PVR_PER_ARCH(spm_init_eot_state)(
134 struct pvr_device *device,
135 struct pvr_spm_eot_state *spm_eot_state,
136 const struct pvr_render_state *rstate,
137 const struct pvr_renderpass_hwsetup_render *hw_render);
138
139 # define pvr_arch_spm_init_eot_state PVR_PER_ARCH(spm_init_eot_state)
140
141 VkResult PVR_PER_ARCH(spm_init_bgobj_state)(
142 struct pvr_device *device,
143 struct pvr_spm_bgobj_state *spm_bgobj_state,
144 const struct pvr_render_state *rstate,
145 const struct pvr_renderpass_hwsetup_render *hw_render);
146
147 # define pvr_arch_spm_init_bgobj_state PVR_PER_ARCH(spm_init_bgobj_state)
148
149 #endif /* PVR_PER_ARCH */
150
151 #endif /* PVR_SPM_H */