ecde3da4648259d5426c8c57008117ac7a7b8967
2 * Copyright (C) 2019 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
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
18 * THE 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
23 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
29 #include "util/u_math.h"
30 #include "pan_encoder.h"
32 /* Compute shaders are invoked with a gl_NumWorkGroups X/Y/Z triplet. Vertex
33 * shaders, it turns out, are invoked with the same mechanism, with the triplet
34 * (1, vertex_count, instance_count).
36 * Alongside this triplet is the gl_WorkGroupSize X/Y/Z triplet.
38 * Unfortunately, the packing for these triplet into the
39 * mali_vertex_tiler_prefix is a little funky, using a dynamic bitfield. The
40 * routines here exist to pack this */
43 panfrost_pack_work_groups_compute(
44 struct mali_vertex_tiler_prefix
*out
,
53 /* First of all, all 6 values are off-by-one (strictly positive).
54 * Account for that, first by ensuring all values are strictly positive
55 * and then by offsetting */
65 num_x
= MALI_POSITIVE(num_x
);
66 num_y
= MALI_POSITIVE(num_y
);
67 num_z
= MALI_POSITIVE(num_z
);
69 size_x
= MALI_POSITIVE(size_x
);
70 size_y
= MALI_POSITIVE(size_y
);
71 size_z
= MALI_POSITIVE(size_z
);
73 /* Next up is to pack in order */
77 /* The values needing packing, in order, and the corresponding shifts.
78 * Indicies into shift are off-by-one to make the logic easier */
80 unsigned shifts
[7] = { 0 };
81 unsigned values
[6] = { size_x
, size_y
, size_z
, num_x
, num_y
, num_z
};
83 for (unsigned i
= 0; i
< 6; ++i
) {
84 /* OR it in, shifting as required */
85 packed
|= (values
[i
] << shifts
[i
]);
87 /* How many bits did we use? */
88 unsigned bit_count
= util_logbase2_ceil(values
[i
] + 1);
90 /* Set the next shift accordingly */
91 shifts
[i
+ 1] = shifts
[i
] + bit_count
;
94 /* Quirk: for non-instanced graphics, the blob sets workgroups_z_shift
95 * = 32. This doesn't appear to matter to the hardware, but it's good
96 * to be bit-identical. */
98 if (quirk_graphics
&& (num_z
<= 1))
101 /* Quirk: for graphics, workgroups_x_shift_2 must be at least 2,
102 * whereas for OpenCL it is simply equal to workgroups_x_shift. For GL
103 * compute, it seems it might *always* be 2, but this is suspicious and
104 * needs further investigation. (I'm probably just using GL wrong). */
106 unsigned shift_2
= shifts
[3];
109 shift_2
= MAX2(shift_2
, 2);
112 uint32_t packed_shifts
=
120 /* Upload the packed bitfields */
121 out
->invocation_count
= packed
;
122 out
->invocation_shifts
= packed_shifts
;
124 /* TODO: Compute workgroups_x_shift_3 */
125 out
->workgroups_x_shift_3
= shift_2
;
128 /* Packs vertex/tiler descriptors simultaneously */
130 panfrost_pack_work_groups_fused(
131 struct mali_vertex_tiler_prefix
*vertex
,
132 struct mali_vertex_tiler_prefix
*tiler
,
140 panfrost_pack_work_groups_compute(vertex
, num_x
, num_y
, num_z
, size_x
, size_y
, size_z
, true);
142 /* Copy results over */
143 tiler
->invocation_count
= vertex
->invocation_count
;
144 tiler
->invocation_shifts
= vertex
->invocation_shifts
;
146 /* Set special fields for each */
147 vertex
->workgroups_x_shift_3
= 5;
148 tiler
->workgroups_x_shift_3
= 6;