Debian Codegraph @

src/imagination/vulkan/pvr_arch_job_compute.c

raw
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 #include <assert.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <vulkan/vulkan.h>
28
29 #include "pvr_border.h"
30 #include "pvr_cmd_buffer.h"
31 #include "pvr_csb.h"
32 #include "pvr_debug.h"
33 #include "pvr_device.h"
34 #include "pvr_job_common.h"
35 #include "pvr_job_context.h"
36 #include "pvr_job_compute.h"
37 #include "pvr_macros.h"
38 #include "pvr_physical_device.h"
39 #include "pvr_types.h"
40 #include "pvr_winsys.h"
41 #include "util/macros.h"
42
43 static void
44 pvr_submit_info_stream_init(struct pvr_compute_ctx *ctx,
45 struct pvr_sub_cmd_compute *sub_cmd,
46 struct pvr_winsys_compute_submit_info *submit_info)
47 {
48 const struct pvr_device *const device = ctx->device;
49 const struct pvr_physical_device *const pdevice = device->pdevice;
50 const struct pvr_device_runtime_info *const dev_runtime_info =
51 &pdevice->dev_runtime_info;
52 const struct pvr_device_info *const dev_info = &pdevice->dev_info;
53 const struct pvr_compute_ctx_switch *const ctx_switch = &ctx->ctx_switch;
54
55 uint32_t *stream_ptr = (uint32_t *)submit_info->fw_stream;
56 uint32_t *stream_len_ptr = stream_ptr;
57
58 /* Leave space for stream header. */
59 stream_ptr += pvr_cmd_length(KMD_STREAM_HDR);
60
61 pvr_csb_pack ((uint64_t *)stream_ptr,
62 CR_TPU_BORDER_COLOUR_TABLE_CDM,
63 value) {
64 value.border_colour_table_address =
65 device->border_color_table->table->vma->dev_addr;
66 }
67 stream_ptr += pvr_cmd_length(CR_TPU_BORDER_COLOUR_TABLE_CDM);
68
69 pvr_csb_pack ((uint64_t *)stream_ptr, CR_CDM_CTRL_STREAM_BASE, value) {
70 value.addr = pvr_csb_get_start_address(&sub_cmd->control_stream);
71 }
72 stream_ptr += pvr_cmd_length(CR_CDM_CTRL_STREAM_BASE);
73
74 pvr_csb_pack ((uint64_t *)stream_ptr, CR_CDM_CONTEXT_STATE_BASE, state) {
75 state.addr = ctx_switch->compute_state_bo->vma->dev_addr;
76 }
77 stream_ptr += pvr_cmd_length(CR_CDM_CONTEXT_STATE_BASE);
78
79 pvr_csb_pack (stream_ptr, CR_CDM_CONTEXT_PDS1, state) {
80 const uint32_t load_program_data_size =
81 PVR_DW_TO_BYTES(ctx_switch->sr[0].pds.load_program.data_size);
82
83 state.pds_seq_dep = false;
84 state.usc_seq_dep = false;
85 state.target = false;
86 state.unified_size = ctx_switch->sr[0].usc.unified_size;
87 state.common_shared = true;
88 state.common_size =
89 DIV_ROUND_UP(sub_cmd->num_shared_regs << 2,
90 ROGUE_CR_CDM_CONTEXT_PDS1_COMMON_SIZE_UNIT_SIZE);
91 state.temp_size = 0;
92
93 assert(load_program_data_size %
94 ROGUE_CR_CDM_CONTEXT_PDS1_DATA_SIZE_UNIT_SIZE ==
95 0);
96 state.data_size =
97 load_program_data_size / ROGUE_CR_CDM_CONTEXT_PDS1_DATA_SIZE_UNIT_SIZE;
98 state.fence = false;
99 }
100 stream_ptr += pvr_cmd_length(CR_CDM_CONTEXT_PDS1);
101
102 if (PVR_HAS_FEATURE(dev_info, compute_morton_capable)) {
103 pvr_csb_pack (stream_ptr, CR_CDM_ITEM, value) {
104 value.mode = 0;
105 }
106 stream_ptr += pvr_cmd_length(CR_CDM_ITEM);
107 }
108
109 if (PVR_HAS_FEATURE(dev_info, cluster_grouping)) {
110 pvr_csb_pack (stream_ptr, CR_COMPUTE_CLUSTER, value) {
111 if (PVR_HAS_FEATURE(dev_info, slc_mcu_cache_controls) &&
112 dev_runtime_info->num_phantoms > 1 && sub_cmd->uses_atomic_ops) {
113 /* Each phantom has its own MCU, so atomicity can only be
114 * guaranteed when all work items are processed on the same
115 * phantom. This means we need to disable all USCs other than
116 * those of the first phantom, which has 4 clusters.
117 */
118 value.mask = 0xFU;
119 } else {
120 value.mask = 0U;
121 }
122 }
123 stream_ptr += pvr_cmd_length(CR_COMPUTE_CLUSTER);
124 }
125
126 if (PVR_HAS_FEATURE(dev_info, tpu_dm_global_registers)) {
127 pvr_csb_pack (stream_ptr, CR_TPU_TAG_CDM_CTRL, value) {}
128 stream_ptr += pvr_cmd_length(CR_TPU_TAG_CDM_CTRL);
129 }
130
131 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) {
132 if (device->pdevice->dev_runtime_info.core_count > 1)
133 pvr_finishme("Emit execute_count, core_count is greater than one");
134 *stream_ptr = 0;
135 stream_ptr++;
136 }
137
138 submit_info->fw_stream_len =
139 (uint8_t *)stream_ptr - (uint8_t *)submit_info->fw_stream;
140 assert(submit_info->fw_stream_len <= ARRAY_SIZE(submit_info->fw_stream));
141
142 pvr_csb_pack ((uint64_t *)stream_len_ptr, KMD_STREAM_HDR, value) {
143 value.length = submit_info->fw_stream_len;
144 }
145 }
146
147 static void pvr_submit_info_ext_stream_init(
148 struct pvr_compute_ctx *ctx,
149 struct pvr_winsys_compute_submit_info *submit_info)
150 {
151 const struct pvr_device_info *const dev_info =
152 &ctx->device->pdevice->dev_info;
153
154 uint32_t *stream_ptr = (uint32_t *)submit_info->fw_stream;
155 uint32_t main_stream_len =
156 pvr_csb_unpack((uint64_t *)stream_ptr, KMD_STREAM_HDR).length;
157 uint32_t *ext_stream_ptr =
158 (uint32_t *)((uint8_t *)stream_ptr + main_stream_len);
159 uint32_t *header0_ptr;
160
161 header0_ptr = ext_stream_ptr;
162 ext_stream_ptr += pvr_cmd_length(KMD_STREAM_EXTHDR_COMPUTE0);
163
164 pvr_csb_pack (header0_ptr, KMD_STREAM_EXTHDR_COMPUTE0, header0) {
165 if (PVR_HAS_QUIRK(dev_info, 49927)) {
166 header0.has_brn49927 = true;
167
168 pvr_csb_pack (ext_stream_ptr, CR_TPU, value) {
169 value.tag_cem_4k_face_packing = true;
170 }
171 ext_stream_ptr += pvr_cmd_length(CR_TPU);
172 }
173 }
174
175 if ((*header0_ptr & ROGUE_KMD_STREAM_EXTHDR_DATA_MASK) != 0) {
176 submit_info->fw_stream_len =
177 (uint8_t *)ext_stream_ptr - (uint8_t *)submit_info->fw_stream;
178 assert(submit_info->fw_stream_len <= ARRAY_SIZE(submit_info->fw_stream));
179 }
180 }
181
182 static void
183 pvr_submit_info_flags_init(const struct pvr_device_info *const dev_info,
184 const struct pvr_sub_cmd_compute *const sub_cmd,
185 struct pvr_winsys_compute_submit_flags *flags)
186 {
187 *flags = (struct pvr_winsys_compute_submit_flags){
188 .prevent_all_overlap = sub_cmd->uses_barrier,
189 .use_single_core = PVR_HAS_FEATURE(dev_info, gpu_multicore_support) &&
190 sub_cmd->uses_atomic_ops,
191 };
192 }
193
194 static void pvr_compute_job_ws_submit_info_init(
195 struct pvr_compute_ctx *ctx,
196 struct pvr_sub_cmd_compute *sub_cmd,
197 struct vk_sync *wait,
198 struct pvr_winsys_compute_submit_info *submit_info)
199 {
200 const struct pvr_device *const device = ctx->device;
201 const struct pvr_device_info *const dev_info = &device->pdevice->dev_info;
202
203 memset(submit_info, 0, sizeof(*submit_info));
204
205 submit_info->frame_num = device->global_queue_present_count;
206 submit_info->job_num = device->global_cmd_buffer_submit_count;
207
208 submit_info->wait = wait;
209
210 pvr_submit_info_stream_init(ctx, sub_cmd, submit_info);
211 pvr_submit_info_ext_stream_init(ctx, submit_info);
212 pvr_submit_info_flags_init(dev_info, sub_cmd, &submit_info->flags);
213 }
214
215 VkResult pvr_arch_compute_job_submit(struct pvr_compute_ctx *ctx,
216 struct pvr_sub_cmd_compute *sub_cmd,
217 struct vk_sync *wait,
218 struct vk_sync *signal_sync)
219 {
220 struct pvr_winsys_compute_submit_info submit_info;
221 struct pvr_device *device = ctx->device;
222
223 pvr_compute_job_ws_submit_info_init(ctx, sub_cmd, wait, &submit_info);
224
225 #ifdef PVR_BUILD_ARCH_ROGUE
226 if (PVR_IS_DEBUG_SET(DUMP_CONTROL_STREAM)) {
227 pvr_csb_dump(&sub_cmd->control_stream,
228 submit_info.frame_num,
229 submit_info.job_num);
230 }
231 #endif
232
233 return device->ws->ops->compute_submit(ctx->ws_ctx,
234 &submit_info,
235 &device->pdevice->dev_info,
236 signal_sync);
237 }