Debian Codegraph @

src/panfrost/libpan/indirect_dispatch.cl

raw
1 /*
2 * Copyright 2024 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "compiler/libcl/libcl.h"
7 #include "compiler/libcl/libcl_vk.h"
8 #include "genxml/gen_macros.h"
9 #include "lib/pan_encoder.h"
10
11 #if (PAN_ARCH >= 6 && PAN_ARCH <= 9)
12 KERNEL(1)
13 panlib_indirect_dispatch(constant VkDispatchIndirectCommand *cmd,
14 uint32_t size_x, uint32_t size_y, uint32_t size_z,
15 global uint8_t *indirect_job,
16 global uint32_t *num_wg_sysval_x,
17 global uint32_t *num_wg_sysval_y,
18 global uint32_t *num_wg_sysval_z)
19 {
20 const uint32_t num_x = cmd->x;
21 const uint32_t num_y = cmd->y;
22 const uint32_t num_z = cmd->z;
23
24 /* In case there is nothing to dispatch, set a null job otherwise we ensure
25 * that the type is compute */
26 const bool is_no_op = num_x * num_y * num_z == 0;
27 struct mali_job_header_packed job_header;
28
29 pan_pack(&job_header, JOB_HEADER, cfg) {
30 cfg.type = is_no_op ? MALI_JOB_TYPE_NULL : MALI_JOB_TYPE_COMPUTE;
31 }
32 pan_merge((global struct mali_job_header_packed *)indirect_job, &job_header, JOB_HEADER);
33
34 /* If there is nothing else to do, let's just return now */
35 if (is_no_op)
36 return;
37
38 #if PAN_ARCH == 9
39 global struct mali_compute_payload_packed *payload =
40 (global struct mali_compute_payload_packed *)(indirect_job +
41 pan_section_offset(
42 COMPUTE_JOB, PAYLOAD));
43
44 pan_unpack(payload, COMPUTE_PAYLOAD, unpacked_job_payloads);
45 pan_pack(payload, COMPUTE_PAYLOAD, cfg) {
46 memcpy(&cfg, &unpacked_job_payloads, sizeof(cfg));
47 cfg.workgroup_count_x = num_x;
48 cfg.workgroup_count_y = num_y;
49 cfg.workgroup_count_z = num_z;
50 }
51 #else
52 global struct mali_invocation_packed *invocation =
53 (global struct mali_invocation_packed *)(indirect_job +
54 pan_section_offset(COMPUTE_JOB,
55 INVOCATION));
56
57 pan_pack_work_groups_compute(invocation, num_x, num_y, num_z, size_x,
58 size_y, size_z, false, false);
59 #endif
60
61 *num_wg_sysval_x = num_x;
62 *num_wg_sysval_y = num_y;
63 *num_wg_sysval_z = num_z;
64 }
65 #endif