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_csb.h"
30 #include "pvr_job_common.h"
31 #include "pvr_job_context.h"
32 #include "pvr_job_compute.h"
33 #include "pvr_private.h"
34 #include "pvr_winsys.h"
35 #include "util/macros.h"
36
pvr_compute_job_ws_submit_info_init(struct pvr_compute_ctx * ctx,struct pvr_sub_cmd * sub_cmd,const VkSemaphore * semaphores,uint32_t semaphore_count,uint32_t * stage_flags,struct pvr_winsys_compute_submit_info * submit_info)37 static void pvr_compute_job_ws_submit_info_init(
38 struct pvr_compute_ctx *ctx,
39 struct pvr_sub_cmd *sub_cmd,
40 const VkSemaphore *semaphores,
41 uint32_t semaphore_count,
42 uint32_t *stage_flags,
43 struct pvr_winsys_compute_submit_info *submit_info)
44 {
45 const struct pvr_compute_ctx_switch *const ctx_switch = &ctx->ctx_switch;
46 uint32_t shared_regs = sub_cmd->compute.num_shared_regs;
47
48 submit_info->frame_num = ctx->device->global_queue_present_count;
49 submit_info->job_num = ctx->device->global_queue_job_count;
50
51 submit_info->semaphores = semaphores;
52 submit_info->semaphore_count = semaphore_count;
53 submit_info->stage_flags = stage_flags;
54
55 /* Other registers are initialized in pvr_sub_cmd_compute_job_init(). */
56 pvr_csb_pack (&submit_info->regs.cdm_resume_pds1,
57 CR_CDM_CONTEXT_PDS1,
58 state) {
59 /* Convert the data size from dwords to bytes. */
60 const uint32_t load_program_data_size =
61 ctx_switch->sr[0].pds.load_program.data_size * 4U;
62
63 state.pds_seq_dep = false;
64 state.usc_seq_dep = false;
65 state.target = false;
66 state.unified_size = ctx_switch->sr[0].usc.unified_size;
67 state.common_shared = true;
68 state.common_size =
69 DIV_ROUND_UP(shared_regs << 2,
70 PVRX(CR_CDM_CONTEXT_PDS1_COMMON_SIZE_UNIT_SIZE));
71 state.temp_size = 0;
72
73 assert(load_program_data_size %
74 PVRX(CR_CDM_CONTEXT_PDS1_DATA_SIZE_UNIT_SIZE) ==
75 0);
76 state.data_size =
77 load_program_data_size / PVRX(CR_CDM_CONTEXT_PDS1_DATA_SIZE_UNIT_SIZE);
78 state.fence = false;
79 }
80 }
81
pvr_compute_job_submit(struct pvr_compute_ctx * ctx,struct pvr_sub_cmd * sub_cmd,const VkSemaphore * semaphores,uint32_t semaphore_count,uint32_t * stage_flags,struct pvr_winsys_syncobj ** const syncobj_out)82 VkResult pvr_compute_job_submit(struct pvr_compute_ctx *ctx,
83 struct pvr_sub_cmd *sub_cmd,
84 const VkSemaphore *semaphores,
85 uint32_t semaphore_count,
86 uint32_t *stage_flags,
87 struct pvr_winsys_syncobj **const syncobj_out)
88 {
89 struct pvr_device *device = ctx->device;
90
91 pvr_compute_job_ws_submit_info_init(ctx,
92 sub_cmd,
93 semaphores,
94 semaphore_count,
95 stage_flags,
96 &sub_cmd->compute.submit_info);
97
98 return device->ws->ops->compute_submit(ctx->ws_ctx,
99 &sub_cmd->compute.submit_info,
100 syncobj_out);
101 }
102