1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2022 Imagination Technologies Ltd.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
5bf215546Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal
6bf215546Sopenharmony_ci * in the Software without restriction, including without limitation the rights
7bf215546Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8bf215546Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is
9bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18bf215546Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include <assert.h>
25bf215546Sopenharmony_ci#include <stdbool.h>
26bf215546Sopenharmony_ci#include <stdint.h>
27bf215546Sopenharmony_ci#include <vulkan/vulkan.h>
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "pvr_csb.h"
30bf215546Sopenharmony_ci#include "pvr_job_common.h"
31bf215546Sopenharmony_ci#include "pvr_job_context.h"
32bf215546Sopenharmony_ci#include "pvr_job_compute.h"
33bf215546Sopenharmony_ci#include "pvr_private.h"
34bf215546Sopenharmony_ci#include "pvr_winsys.h"
35bf215546Sopenharmony_ci#include "util/macros.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistatic void pvr_compute_job_ws_submit_info_init(
38bf215546Sopenharmony_ci   struct pvr_compute_ctx *ctx,
39bf215546Sopenharmony_ci   struct pvr_sub_cmd_compute *sub_cmd,
40bf215546Sopenharmony_ci   struct vk_sync **waits,
41bf215546Sopenharmony_ci   uint32_t wait_count,
42bf215546Sopenharmony_ci   uint32_t *stage_flags,
43bf215546Sopenharmony_ci   struct pvr_winsys_compute_submit_info *submit_info)
44bf215546Sopenharmony_ci{
45bf215546Sopenharmony_ci   const struct pvr_compute_ctx_switch *const ctx_switch = &ctx->ctx_switch;
46bf215546Sopenharmony_ci   uint32_t shared_regs = sub_cmd->num_shared_regs;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   submit_info->frame_num = ctx->device->global_queue_present_count;
49bf215546Sopenharmony_ci   submit_info->job_num = ctx->device->global_queue_job_count;
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   submit_info->waits = waits;
52bf215546Sopenharmony_ci   submit_info->wait_count = wait_count;
53bf215546Sopenharmony_ci   submit_info->stage_flags = stage_flags;
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   pvr_csb_pack (&submit_info->regs.cdm_ctx_state_base_addr,
56bf215546Sopenharmony_ci                 CR_CDM_CONTEXT_STATE_BASE,
57bf215546Sopenharmony_ci                 state) {
58bf215546Sopenharmony_ci      state.addr = ctx_switch->compute_state_bo->vma->dev_addr;
59bf215546Sopenharmony_ci   }
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   /* Other registers are initialized in pvr_sub_cmd_compute_job_init(). */
62bf215546Sopenharmony_ci   pvr_csb_pack (&submit_info->regs.cdm_resume_pds1,
63bf215546Sopenharmony_ci                 CR_CDM_CONTEXT_PDS1,
64bf215546Sopenharmony_ci                 state) {
65bf215546Sopenharmony_ci      /* Convert the data size from dwords to bytes. */
66bf215546Sopenharmony_ci      const uint32_t load_program_data_size =
67bf215546Sopenharmony_ci         ctx_switch->sr[0].pds.load_program.data_size * 4U;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci      state.pds_seq_dep = false;
70bf215546Sopenharmony_ci      state.usc_seq_dep = false;
71bf215546Sopenharmony_ci      state.target = false;
72bf215546Sopenharmony_ci      state.unified_size = ctx_switch->sr[0].usc.unified_size;
73bf215546Sopenharmony_ci      state.common_shared = true;
74bf215546Sopenharmony_ci      state.common_size =
75bf215546Sopenharmony_ci         DIV_ROUND_UP(shared_regs << 2,
76bf215546Sopenharmony_ci                      PVRX(CR_CDM_CONTEXT_PDS1_COMMON_SIZE_UNIT_SIZE));
77bf215546Sopenharmony_ci      state.temp_size = 0;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci      assert(load_program_data_size %
80bf215546Sopenharmony_ci                PVRX(CR_CDM_CONTEXT_PDS1_DATA_SIZE_UNIT_SIZE) ==
81bf215546Sopenharmony_ci             0);
82bf215546Sopenharmony_ci      state.data_size =
83bf215546Sopenharmony_ci         load_program_data_size / PVRX(CR_CDM_CONTEXT_PDS1_DATA_SIZE_UNIT_SIZE);
84bf215546Sopenharmony_ci      state.fence = false;
85bf215546Sopenharmony_ci   }
86bf215546Sopenharmony_ci}
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ciVkResult pvr_compute_job_submit(struct pvr_compute_ctx *ctx,
89bf215546Sopenharmony_ci                                struct pvr_sub_cmd_compute *sub_cmd,
90bf215546Sopenharmony_ci                                struct vk_sync **waits,
91bf215546Sopenharmony_ci                                uint32_t wait_count,
92bf215546Sopenharmony_ci                                uint32_t *stage_flags,
93bf215546Sopenharmony_ci                                struct vk_sync *signal_sync)
94bf215546Sopenharmony_ci{
95bf215546Sopenharmony_ci   struct pvr_device *device = ctx->device;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   pvr_compute_job_ws_submit_info_init(ctx,
98bf215546Sopenharmony_ci                                       sub_cmd,
99bf215546Sopenharmony_ci                                       waits,
100bf215546Sopenharmony_ci                                       wait_count,
101bf215546Sopenharmony_ci                                       stage_flags,
102bf215546Sopenharmony_ci                                       &sub_cmd->submit_info);
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci   return device->ws->ops->compute_submit(ctx->ws_ctx,
105bf215546Sopenharmony_ci                                          &sub_cmd->submit_info,
106bf215546Sopenharmony_ci                                          signal_sync);
107bf215546Sopenharmony_ci}
108